1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

My theme doesn't support open graph, what now?

Discussion in 'Blogging' started by roki4ka, Apr 18, 2017.

  1. roki4ka

    roki4ka Senior Member

    Joined:
    Jun 20, 2016
    Messages:
    888
    Likes Received:
    649
    When I shared my home page on FB there wasn't any image.

    I have put this code in the child theme functions.php:
    Code:
    <?php
    function add_opengraph_markup() {
      if (is_single()) {
        global $post;
        if(get_the_post_thumbnail($post->ID, 'thumbnail')) {
          $thumbnail_id = get_post_thumbnail_id($post->ID);
          $thumbnail_object = get_post($thumbnail_id);
          $image = $thumbnail_object->guid;
        } else {
          // set default image
          $image = '';
        }
        //$description = get_bloginfo('description');
        $description = substr(strip_tags($post->post_content),0,200) . '...';
    ?>
    <meta property="og:title" content="<?php the_title(); ?>" />
    <meta property="og:type" content="article" />
    <meta property="og:image" content="<?=$image?>" />
    <meta property="og:url" content="<?php the_permalink(); ?>" />
    <meta property="og:description" content="<?=$description?>" />
    <meta property="og:site_name" content="<?=get_bloginfo('name')?>" />
    
    <?php
      }
    }
    add_action('wp_head', 'add_opengraph_markup');
    ?>
    + the meta properties in themeheader.php in the parent theme where u specify image url, title, name etc etc.

    I have tried with over 10 plugins including Yoast and specialized for the purpose and nothing helps.

    I have searched google for over 2 hours and reading tens of pages and their solutions don't work for me.

    P.S The meta properties were woking for g+ but not for facebook. Actually I have linked the website in telegram also and it was displaying the og meta property that I have added. Only Facebook gives me problems.
     
  2. blogzandstuff

    blogzandstuff Elite Member

    Joined:
    Jan 1, 2015
    Messages:
    6,423
    Likes Received:
    2,998
    Occupation:
    blog creator
    Location:
    UK
    Have you run your url through the debug tool? It will show you what's wrong
     
  3. SEO

    SEO Jr. VIP Jr. VIP

    Joined:
    Jan 6, 2017
    Messages:
    865
    Likes Received:
    649
    Yeah, Yoast should take care of that for you. Open Graph and Twitter cards all cache. Use the Open Graph debug tool. You'll be pulling your hair out because of the cache.
     
  4. roki4ka

    roki4ka Senior Member

    Joined:
    Jun 20, 2016
    Messages:
    888
    Likes Received:
    649
    Yes, it doesn't show any error : /
     
  5. roki4ka

    roki4ka Senior Member

    Joined:
    Jun 20, 2016
    Messages:
    888
    Likes Received:
    649
    Changed the theme until I find solution :(