The embed_head WordPress PHP action allows you to insert custom scripts or data into the head tag of the embed template.
Usage
add_action('embed_head', 'your_function_name');
function your_function_name() {
// your custom code here
}
Parameters
- None
More information
See WordPress Developer Resources: embed_head
Examples
Add a custom CSS style to the embed template head
This code adds a custom CSS style to change the background color of the embed template.
add_action('embed_head', 'add_custom_css_style');
function add_custom_css_style() {
echo '<style>body { background-color: #f5f5f5; }</style>';
}
Add a Google Analytics tracking code
This code adds Google Analytics tracking code to the embed template head.
add_action('embed_head', 'add_google_analytics');
function add_google_analytics() {
echo "<script async src='https://www.googletagmanager.com/gtag/js?id=UA-XXXXXX-Y'></script>";
echo "<script>window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXXXX-Y');</script>";
}
Add custom meta tags
This code adds custom meta tags for description and keywords to the embed template head.
add_action('embed_head', 'add_custom_meta_tags');
function add_custom_meta_tags() {
echo '<meta name="description" content="A custom description for the embedded post">';
echo '<meta name="keywords" content="wordpress, embed, custom">';
}
Add a custom JavaScript file
This code adds a custom JavaScript file to the embed template head.
add_action('embed_head', 'add_custom_js');
function add_custom_js() {
echo '<script src="/path/to/your/custom.js"></script>';
}
Add a custom favicon
This code adds a custom favicon to the embed template head.
add_action('embed_head', 'add_custom_favicon');
function add_custom_favicon() {
echo '<link rel="icon" href="/path/to/your/favicon.ico" type="image/x-icon">';
}