Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save FellowshipAgency/406fceb465e3ac461ae4d5edd95d4a91 to your computer and use it in GitHub Desktop.
Save FellowshipAgency/406fceb465e3ac461ae4d5edd95d4a91 to your computer and use it in GitHub Desktop.
<?php
/**
* Filters default image arguments for TSF.
*
* @param array $defaults The image defaults.
* @param array $args The image callback arguments.
*/
add_filter( 'the_seo_framework_og_image_args', function( $defaults, $args = array() ) {
if ( function_exists( 'is_product_category' ) ) {
if ( is_product_category() ) {
global $wp_query;
$cat = $wp_query->get_queried_object();
$thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
$image = wp_get_attachment_url( $thumbnail_id );
if ( $image ) {
$defaults['image'] = $image;
}
}
}
return $defaults;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment