Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #957738

    I am reading about how to put the meta in place in order to have Facebook display the desired content when a URL is mentioned on Facebook. Meta tags are available for things like title, description, and an image, for example. I modified the functions.php file in the child theme and I also tried putting one line of meta for the image into the parent-level header.php file, with no success.

    #958673

    Hey JZNAMZ,

    Can you share with us the code that you’re trying to use?

    Could you please give us a link to your website, we need more context to be able to help you.

    Best regards,
    Victoria

    #958793

    I tried using some PHP code that I had found on the Internet. I ended up removing this particular code from the child theme functions.php file, and I started using the Yoast SEO plugin. The Yoast plugin seems to provide the meta functionality for Facebook.

    Here is the code that did not seem to work:

    function add_opengraph_doctype( $output ) {
            return $output . ' xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml"';
        }
    add_filter('language_attributes', 'add_opengraph_doctype');
     
    //Lets add Open Graph Meta Info
     
    function insert_fb_in_head() {
        global $post;
        if ( !is_singular()) //if it is not a post or a page
            return;
            echo '<meta property="fb:admins" content="1600152201"/>';
            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="og:site_name" content="Namz Custom Cycle Products"/>';
        if(!has_post_thumbnail( $post->ID )) { //the post does not have featured image, use a default image
            $default_image="https://new.namzcustomcycleproducts.com/staging/wp-content/uploads/2018/05/namz-fb.jpg"; //replace this with a default image on your server or an image in your media library
            echo '<meta property="og:image" content="' . $default_image . '"/>';
        }
        else{
            $thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'medium' );
            echo '<meta property="og:image" content="' . esc_attr( $thumbnail_src[0] ) . '"/>';
        }
        echo "
    ";
    }
    add_action( 'wp_head', 'insert_fb_in_head', 5 );
    #959183

    Hi JZNAMZ,

    So did you get it working for you with the Yoast Seo plugin?

    Best regards,
    Victoria

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.