Display custom field on front-end


I have a custom field for my posts which I would like to show on the front-end. Is it possible to do this, if the post is already published?

My understanding so far is that custom field are solely for back-end and requiring them to show on the front-end requires coding on the single.php.


  • Michelle Shull
    • DEV MAN’s Apprentice

    Hi, Tano!

    You're correct, you do need to add a little code to the template you want your custom field to appear on, but it's actually not as complicated as it might seem.

    IN Custom Press, you'll be able to copy the code you need to your clipboard, or a blank notepad file. It will be on the same page as your custom field, and looks like this:

    <?php echo do_shortcode('[custom_fields_block]'); ?>

    You'll edit the part between the two braces: custom_field_block and replace it with the Field ID for your custom field. (You'll see it to the right of your custom field names on the custom field page.)

    Now open the single.php template where you want the contents of this field to display. (single.php will be for all regular (blog) posts.)

    Scan the file and you'll get an idea of what the different pieces do. Look for a line that says "end loop" or something similar. You're going to paste the code above (with your ID) somewhere ABOVE that line, and somewhere BELOW where the loop is started. (The Loop is what generates the main content block on any post or page.) The placement otherwise is up to you, and will depend on where in the post you want this to appear.

    This will apply to all previously posted single posts, as well as to any new posts you create.

    This is a great place to use a child theme, if you're not already, because you can copy single.php into your child theme folder, and it won't be overwritten when your theme updates.

    Hope this helps!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.