WooCommerce Facebook Like Share Button
[resolved] Escape attribute in Facebook OpenGraph correctly (3 posts)

  1. Torsten Landsiedel
    Posted 2 years ago #

    If there are quotes in the text for the FB open graph description it is not sufficient to just strip the tags:
    <meta property="og:description" content="<?php echo strip_tags(get_the_excerpt($post->ID)); ?>" />

    You have to care about the quotes and use "htmlentities", too.

    Better: You can use the WP function for this, called esc_attr:

    If you use this line:
    <meta property="og:description" content="<?php echo esc_attr( strip_tags( get_the_excerpt($post->ID) ) ); ?>" />
    there are no problems with quotes anymore!

    And the thumbnail image is (if not changed from the standard 150x150) to small for Facebook:

    og:image should be larger: Provided og:image is not big enough. Please use an image that's at least 200x200 px. Image 'http://dev.langhans-suppenmanufaktur.de/wp-content/uploads/langhans_produkt_0001-10.jpg' will be used instead.

    As Facebook is using the original version of the image anyway, we could set it on the page, too:

    <meta property="og:image" content="<?php echo wp_get_attachment_url(get_post_thumbnail_id($post->ID)); ?>" />
    <link rel="image_src" href="<?php echo wp_get_attachment_url(get_post_thumbnail_id($post->ID)); ?>" />

    Or you could use at least the medium version (minimum 200x200 for FB).

    Best regards


  2. terrytsang
    Plugin Author

    Posted 2 years ago #

    Hi Torsten, thanks for the tips. I have updated the code.

  3. Torsten Landsiedel
    Posted 2 years ago #

    Great! :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WooCommerce Facebook Like Share Button
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic