Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add custom Facebook Social Share images for Yoast SEO for Archive pages
<?php
/* @link https://anythinggraphic.net/yoast-seo-add-custom-social-share-images-for-archive-category-pages-in-wordpress
/* Add custom Facebook Social Share images for Yoast SEO for Archive pages
----------------------------------------------------------------------------------------*/
add_filter( 'wpseo_opengraph_image', 'ag_yoast_seo_fb_share_images', 10, 1 );
function ag_yoast_seo_fb_share_images( $img ) {
if( is_post_type_archive( 'archivename') ) {
$img = get_stylesheet_directory_uri().'/images/your-image-file.jpg';
}
if( is_category( 'categoryname') ) {
$img = get_stylesheet_directory_uri().'/images/your-image-file.jpg';
}
return $img;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment