Using WordPress ‘print_embed_styles()’ PHP function

The print_embed_styles() WordPress PHP function prints the CSS in the embed iframe header.

Usage

print_embed_styles();

Parameters

  • None

More information

See WordPress Developer Resources: print_embed_styles()

Examples

Add custom CSS to the embed iframe

Add the following code to your theme’s functions.php file to add custom CSS to the embed iframe.

function my_custom_embed_styles() {
    echo '<style>
        /* Custom CSS goes here */
        body {
            background-color: #f5f5f5;
        }
    </style>';
}
add_action('embed_head', 'my_custom_embed_styles');

Change font family and size

Add the following code to your theme’s functions.php file to change the font family and size for embeds.

function change_embed_font() {
    echo '<style>
        body {
            font-family: Arial, sans-serif;
            font-size: 16px;
        }
    </style>';
}
add_action('embed_head', 'change_embed_font');

Customize the post title appearance

Add the following code to your theme’s functions.php file to customize the post title appearance in the embed iframe.

function customize_embed_title() {
    echo '<style>
        .wp-embed-heading {
            font-size: 24px;
            font-weight: bold;
            color: #333;
        }
    </style>';
}
add_action('embed_head', 'customize_embed_title');

Hide the post meta information

Add the following code to your theme’s functions.php file to hide the post meta information in the embed iframe.

function hide_embed_post_meta() {
    echo '<style>
        .wp-embed-meta {
            display: none;
        }
    </style>';
}
add_action('embed_head', 'hide_embed_post_meta');

Add the following code to your theme’s functions.php file to customize the styling of the embedded featured image.

function customize_embed_featured_image() {
    echo '<style>
        .wp-embed-featured-image {
            border: 1px solid #ccc;
            padding: 5px;
            margin-bottom: 10px;
        }
    </style>';
}
add_action('embed_head', 'customize_embed_featured_image');