Support » Plugins and Hacks » Hacks » Using custom fields for meta tags (thumbnails) in header?

  • Hi guys

    I’m trying to replace the value of a meta tag with something dynamic.

    This is the code i wish to change:
    <meta property="og:image" content="http://www.gallozone.co.za/wp-content/uploads/2010/08/gallozone.jpg" />

    I would like the value of that meta tag to be something unique for every post.

    A custom field maybe?

    I would like to add a custom field in my post edit area along with a value (the url of a thumbnail image) and then I would like it to appear in the meta tag.

    How can I have this done?
    Is there a way to assign a unique meta tag to each post?

Viewing 3 replies - 1 through 3 (of 3 total)
  • So there is no wordpress wizard who knows the answer to this?

    I’m no PHP superstar, but I did string this together and it works on my site at least.

    ___

    In the header.php, before the </head> tag.

    <!-- Facebook Open Graph Image -->
    <?php if(get_post_meta($post->ID, 'fb_img')){ ?>
    <meta property="og:image" content="<?php echo get_post_meta($post->ID, 'fb_img', $single = true); ?>" />
    <?php } else { ?>
    <meta property="og:image" content="http://www.THE-URL-OF-THE-DEFAULT-IMAGE" />
    <?php } ?>

    fb_img – This is the custom field name. Use the full url (starting with “http://”) in the “value” field.

    http://www.THE-URL-OF-THE-DEFAULT-IMAGE – enter the url of the default image to be used when no image is set as a custom field.

    I’ve also used the following successfully.

    Control the title appearing on shared content and Facebook Comments plugin.
    <meta property="og:title" content="<?php the_title() ?>" />

    Control the url appearing on shared content and Facebook Comments plugin.
    <meta property="og:url" content="<?php the_permalink() ?>" />

    I hope this works for you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Using custom fields for meta tags (thumbnails) in header?’ is closed to new replies.