• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

How to incorporate a custom field within entry-content

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › How to incorporate a custom field within entry-content

This topic is: resolved

Tagged: Custom fields, custom post types, custom shortcodes

  • This topic has 4 replies, 3 voices, and was last updated 8 years, 1 month ago by Brad Dalton.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • May 5, 2017 at 10:24 am #205960
    Aleksandr
    Member

    Hi,

    I have been asked to incorporate a custom field within the body text of a post on the Genesis Child Theme.

    Initially I said that this is not possible, but I decided to make sure.

    Is there a way to search entry-content and replace a string in it with a custom field?

    Thank you

    May 5, 2017 at 10:51 am #205962
    Victor Font
    Moderator

    You can create a shortcode to display the field content.


    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    May 5, 2017 at 5:07 pm #205992
    Brad Dalton
    Participant

    Here's some custom field code

    add_action( 'loop_start', 'before_single_post_content' );
    function before_single_post_content() {
    if ( is_singular( 'post') ) {
    $cf = get_post_meta( get_the_ID(), 'custom_field_name', true );
    if( ! empty( $cf ) ) {
    echo '<div class="before-content">'. $cf .'</div>';
        }
      }
    }
    

    Tutorials for StudioPress Themes.

    May 6, 2017 at 3:53 am #206009
    Aleksandr
    Member

    Thanks Victor and Brad. A shortcode is exactly what I need. It needs to output the custom field in a way similar to Brad's example.

    Brad, I notice that in your example you use get_post_meta function, which is a WordPress function. I used the genesis_get_custom_field('field_name') function. Your way seems better because it is based on core functionality - am I correct in this?

    In this case I need this output on a custom post type, so the get_post_meta did not work (I am guessing that was the reason). Do you know of the recommended WordPress way to get metadata for custom post types?

    May 6, 2017 at 9:17 am #206021
    Brad Dalton
    Participant

    The code uses a conditional tag so it only executes on single posts. Its a example of how to print a custom fields value using a hook.

    You'll need to modify the code so it works with add_shortcode so you won't need a conditional tag.

    You can use get_post_meta or genesis_get_custom_field with Genesis.


    Tutorials for StudioPress Themes.

  • Author
    Posts
Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2025 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble