Join the Voxel Guide Community!

Get Involved

Pull Cover Photo for SEO Open Graph Sharing Image

Description/Instructions

This snippet will pull the cover field on your single post and will use that as the OG:IMAGE when sharing the link.

THIS CODE ONLY WORKS WITH SEOPRESS PLUGIN

If this snippet helped, feel free to buy me a taco :)

Instructions

SEOPRESS PLUGIN ONLY

function sp_social_og_thumb_dynamic_multiple_ids($html) {
if (is_single()) {
global $post;
$image_id = get_post_meta($post->ID, 'cover', true); // Retrieve the 'cover' field, assuming it returns a single image ID

if (!empty($image_id)) {
$first_image_url = wp_get_attachment_url($image_id); // Get the full URL of the image

if ($first_image_url) {
$html = '<meta property="og:image" content="' . esc_url($first_image_url) . '" />';
}
}
}
return $html;
}
add_filter('seopress_social_og_thumb', 'sp_social_og_thumb_dynamic_multiple_ids');

  • PHP
Copy Code

Let's Chat About this Snippet

Chat Toggle
Voxel Guide AI
Voxel Guide AI
Voxel Guide AI
Voxel Guide AI
Ask me anything about Voxel!
Send
Powered by AI24