Grow your CSS skills. Land your dream job.

Best Markup for Echoing Custom Fields in WP

  • # September 1, 2011 at 5:54 pm

    Just out of interest, what would be the best way to semantically echo custom fields in a WordPress theme.

    At the moment I’m using this, with “blueberries” being my custom field.

    < ?php
    global $wp_query;
    $postid = $wp_query->post->ID;
    echo get_post_meta($postid, 'blueberries', true);
    ?>

    Courtesy of WPRecipes.

    I guess what I’m asking is, is there a shorter bit of markup I could use?

    # September 1, 2011 at 6:21 pm

    Here are a few examples on this site:
    http://css-tricks.com/snippets/wordpress/using-custom-fields/

    I prefer checking to see if the value exists first, but based on what you’ve posted it doesn’t look like you need that.

    # September 1, 2011 at 9:14 pm

    @TheDoc, Cheers dude!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".