Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
/* @link https://anythinggraphic.net/yoast-seo-add-custom-social-share-images-for-archive-category-pages-in-wordpress
/* Add custom Twitter Social Share images for Yoast SEO for Archive pages
----------------------------------------------------------------------------------------*/
add_filter( 'wpseo_twitter_image', 'ag_yoast_seo_tw_share_images', 10, 1 );
function ag_yoast_seo_tw_share_images( $img ) {
if( is_post_type_archive( 'archivename') ) {
$img = get_stylesheet_directory_uri().'/images/your-image-file.jpg';
}
iif( 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