Skip to content

Instantly share code, notes, and snippets.

@anythinggraphic
Last active October 18, 2020 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anythinggraphic/a9184247476aaf69467b403d3e135ed4 to your computer and use it in GitHub Desktop.
Save anythinggraphic/a9184247476aaf69467b403d3e135ed4 to your computer and use it in GitHub Desktop.
<?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';
}
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