Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #465082

    I am working on a woocommerce site with enfold. And I am trying to a facebook sharing button to each product page. I am trying to add OG meta content to the page header of the product page for facebook sharing. I can get the product name, image, url. However, I want to add og:description content but I don’t know how to do that. I put my product description into the enfold “tab” element. I created 2 tab pages. One is product description and the other one is shipping info. My question is how can I get the content from one of the tab page in the header.php?

    
    <?php $print_og = true; ?>
    <?php if(is_product() && $print_og){ ?>
    <?php $feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>
    <!-- Custom Facebook OG Data Added By Alex -->
    <meta property="og:title" content="<?php echo get_the_title(); ?>" />
    <meta property="og:type" content="product" />
    <meta property="og:url" content="<?php echo get_permalink(); ?>" />
    <meta property="og:image" content="<?php echo $feat_image; ?>" />
    <meta property="og:site_name" content="<?php echo get_bloginfo('name'); ?>" />
    <meta property="og:description" content="how can i put product description here???" />
    <!-- End of custom OG Data -->
    <? } ?>
    
    • This topic was modified 9 years, 5 months ago by boscotwcheung.
    #465210

    I finally made it.

    <?php 
    $print_og = true;
    if(is_product() && $print_og){
    	// get featured image url
    	$feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
    	// get post content
    	$content_post = get_post($post->ID);
    	$product_content = $content_post->post_content;
    	// extract the tab content
    	$pos1 = strpos($product_content, "[av_tab title='DESCRIPTION'");
    	$product_content = substr($product_content, $pos1);
    	$pos2 = strpos($product_content, "[/av_tab]");
    	$len1 = strlen($product_content) - $pos2;
    	$len1 = strlen($product_content) - $len1;
    	$product_content = substr($product_content, 0, $len1);
    	$pos3 = strpos($product_content, "]") + 1;
    	$product_content = substr($product_content, $pos3);
    	// reformat the content: remove newline, html tag, double quote, etc
    	$product_content = str_replace('"', "'", $product_content);
    	$product_content = trim(preg_replace( "/\s+/", " ", $product_content));
    	$product_content = strip_tags($product_content);
    ?>
    <!-- Custom Facebook OG Data Added By Alex -->
    <meta property="og:title" content="<?php echo get_the_title(); ?>" />
    <meta property="og:type" content="product" />
    <meta property="og:url" content="<?php echo get_permalink(); ?>" />
    <meta property="og:image" content="<?php echo $feat_image; ?>" />
    <meta property="og:site_name" content="<?php echo get_bloginfo('name'); ?>" />
    <meta property="og:description" content="<?php echo $product_content; ?>" />
    <!-- End of custom OG Data -->
    <? } ?>
Viewing 2 posts - 1 through 2 (of 2 total)
  • The topic ‘Get Tab content’ is closed to new replies.