Using WordPress ’embed_content_meta’ PHP action

The embed_content_meta WordPress PHP action allows you to insert additional meta content in the embed template.

Usage

add_action('embed_content_meta', 'your_custom_function');
function your_custom_function() {
// your custom code here
}

Parameters

  • None

More information

See WordPress Developer Resources: embed_content_meta

Examples

Add Open Graph Tags

Insert Open Graph tags to the embed content meta for better sharing on social media platforms.

add_action('embed_content_meta', 'add_open_graph_tags');
function add_open_graph_tags() {
    global $post;
    echo '<meta property="og:title" content="' . get_the_title($post->ID) . '">';
    echo '<meta property="og:description" content="' . get_the_excerpt($post->ID) . '">';
    echo '<meta property="og:url" content="' . get_permalink($post->ID) . '">';
}

Add Twitter Card Meta Tags

Add Twitter card meta tags to enhance how your content is displayed when shared on Twitter.

add_action('embed_content_meta', 'add_twitter_card_meta');
function add_twitter_card_meta() {
    global $post;
    echo '<meta name="twitter:card" content="summary_large_image">';
    echo '<meta name="twitter:title" content="' . get_the_title($post->ID) . '">';
    echo '<meta name="twitter:description" content="' . get_the_excerpt($post->ID) . '">';
    echo '<meta name="twitter:image" content="' . get_the_post_thumbnail_url($post->ID) . '">';
}

Add Custom Meta Tag

Insert a custom meta tag for your specific use case.

add_action('embed_content_meta', 'add_custom_meta_tag');
function add_custom_meta_tag() {
    echo '<meta name="custom-meta" content="Some custom content">';
}

Add a canonical link to the embedded content to help search engines understand the original source.

add_action('embed_content_meta', 'add_canonical_link');
function add_canonical_link() {
    global $post;
    echo '<link rel="canonical" href="' . get_permalink($post->ID) . '">';
}

Add Custom CSS to Embed Template

Inject custom CSS directly into the embed template to style the content.

add_action('embed_content_meta', 'add_custom_css');
function add_custom_css() {
echo '<style>
.wp-embed {
background-color: #f5f5f5;
color: #333;
font-family: "Arial", sans-serif;
}
</style>';
}