Created
April 29, 2015 20:25
-
-
Save mch0lic/4cb82d7fcdc47c19c7c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Category and product tag og:image fix for SEO by yoast / woocommerce | |
*/ | |
function fabframe_print_custom_og_image() | |
{ | |
if ( is_product_category() ) { | |
global $post; | |
$args = array( 'taxonomy' => 'product_cat',); | |
$terms = wp_get_post_terms( $post->ID, 'product_cat', $args ); | |
if ( count( $terms ) > 0 ) { | |
$og_image = get_field( 'custom_og_image', 'product_cat_' . $terms[0]->term_id ); | |
if ( $og_image ) { | |
printf( '<meta property="og:image" content="%s" />', $og_image ); | |
} | |
} | |
} | |
if ( is_product_tag() ) { | |
global $post; | |
$args = array( 'taxonomy' => 'product_tag',); | |
$terms = wp_get_post_terms( $post->ID, 'product_tag', $args ); | |
if ( count( $terms ) > 0 ) { | |
$og_image = get_field( 'custom_og_image', 'product_tag_' . $terms[0]->term_id ); | |
if ( $og_image ) { | |
printf( '<meta property="og:image" content="%s" />', $og_image ); | |
} | |
} | |
} | |
} | |
add_action( 'wp_head', 'fabframe_print_custom_og_image' ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment