WordPress.org

Ready to get started?Download WordPress

Forums

Using custom fields for meta tags (thumbnails) in header? (4 posts)

  1. gzone1000
    Member
    Posted 3 years ago #

    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?

  2. gzone1000
    Member
    Posted 3 years ago #

    So there is no wordpress wizard who knows the answer to this?

  3. starfly
    Member
    Posted 3 years ago #

    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.

  4. starfly
    Member
    Posted 3 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic