• Resolved radupl

    (@radupl)


    Hello,

    I’m trying to manually add Open Graph Meta info in the functions.php of my child theme, but I’m having trouble adding the brand name in there.

    Here’s a snippet of the code:

    function facebook_open_graph() {
    	    global $post;
    
    	        echo '<meta property="og:title" content="' . get_the_title() . '"/>';
    	        echo '<meta property="og:type" content="article"/>';
    	        echo '<meta property="og:url" content="' . get_permalink() . '"/>';
    	        echo '<meta property="product:condition" content="new"/>';
    	        echo '<meta property="product:brand" content="' . get_pwb-brand() . '"/>';
    }
    

    Obviously what I tried didn’t work, so I was wondering if you could help me with the code that I need to input there to get the brand as well into the meta?

Viewing 1 replies (of 1 total)
  • Plugin Contributor titodevera

    (@titodevera)

    Hi radupl

    You can try something like this:

    
    add_action('wp_head', function(){
    	if( !is_product() ) return;
    
    	$product_id     = get_the_ID();
    	$product_brands = wp_get_post_terms( $product_id, 'pwb-brand', array( 'fields' => 'names' ) );
    
    	foreach( $product_brands as $brand )
    		echo '<meta property="product:brand" content="' . $brand . '"/>';
    });
    

    ??

Viewing 1 replies (of 1 total)
  • The topic ‘How to get brand’ is closed to new replies.