• 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

Add Custom Fields To Genesis Child Theme

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 › Add Custom Fields To Genesis Child Theme

This topic is: not resolved

Tagged: custom field, genesis_get_custom_field, get_post_meta

  • This topic has 4 replies, 2 voices, and was last updated 7 years, 2 months ago by ashleymichelle.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • April 23, 2018 at 2:38 pm #219204
    ashleymichelle
    Member

    I am having a lot of difficulty adding custom fields to my theme; I would like to use the built-in Custom Fields feature on the WordPress Posts page, and simply insert the value per post.

    This is what I was previously using within my Single Post loop before switching to Genesis Framework:

    <?php $affiliates = get_post_meta ($post->ID, 'affiliates', true); ?>
    <?php if (strlen ($affiliates) > 0): ?>
       <?php echo '<a href="/./affiliates" target="_blank">affiliate link</a>'; ?>
    <?php endif; ?>
    
    <?php $prpost = get_post_meta ($post->ID, 'prpost', true); ?>
    <?php if (strlen ($prpost) > 0): ?>
       <?php echo '<a class="prpost" href="/./pr" target="_blank">PR</a>'; ?>
    <?php endif; ?>
    
    <?php $prsample = get_post_meta ($post->ID, 'prsample', true); ?>
    <?php if (strlen ($prsample) > 0): ?>
       <?php echo '<a class="prsample" href="/./pr" target="_blank">Gift</a>'; ?>
    <?php endif; ?>
    
    <?php if(get_post_meta($post->ID, "buyit", true)): { ?>
                <?php $field_name="buyit"; $field_value = get_post_meta($post->ID, $field_name, true); ?>
                <a class="buyit" href="<?php echo $field_value; ?>" target="_blank">Get It Here</a>
                <?php ; } endif ?>

    Each of these displayed a different value and were positioned in various places on my theme. I just need to figure out how to accomplish this general concept with the Genesis Framework, as this tutorial isn't quite doing what I need it to.

    I would like the custom fields displayed on both the Post, and also beneath the expert on the Main Index, below each Post Image, but above the excerpt and "Read More" link.

    Thanks so much!

    http://ohmybonbon.com
    April 24, 2018 at 12:25 am #219208
    Brad Dalton
    Participant

    Use the code you linked to as its tested and works.

    The hook determines which position the custom field value outputs on the front end.


    Tutorials for StudioPress Themes.

    April 24, 2018 at 6:27 pm #219244
    ashleymichelle
    Member

    Hi Brad,
    I did figure out how to implement it; Genesis newbie here.

    However, my next question is, how do I consolidate all of this into one hook, so that I can apply a single class? I'd like to wrap all of this within a divider, ".awrap"...

    add_action( 'genesis_before_entry_content', 'affiliate_link', 12 );
    function affiliate_link() {
    
    if ( is_single() )
    
        $value = get_post_meta( get_the_ID(), 'affiliates', true );
        
        if ( ! empty( $value ) ) {
        
        echo '<span class="awrap"><a href="/./affiliates" target="_blank">affiliate link</a></span>';
        
        }
    }
    
    add_action( 'genesis_before_entry_content', 'pr_sample', 12 );
    function pr_sample() {
    
    if ( is_single() )
    
        $value = get_post_meta( get_the_ID(), 'prsample', true );
        
        if ( ! empty( $value ) ) {
        
        echo '<span class="awrap"><a class="prsample" href="/./pr" target="_blank">gift</a></span>';
        
        }
    }
    
    add_action( 'genesis_before_entry_content', 'pr_post', 12 );
    function pr_post() {
    
    if ( is_single() )
    
        $value = get_post_meta( get_the_ID(), 'prpost', true );
        
        if ( ! empty( $value ) ) {
        
        echo '<span class="awrap"><a class="prpost" href="/./pr" target="_blank">PR</a></span>';
        
        }
    }
    
    add_action( 'genesis_before_entry_content', 'buy_it', 12 );
    function buy_it() {
    
    if ( is_single() )
    
        $value = get_post_meta( get_the_ID(), 'buyit', true );
        
        if ( ! empty( $value ) ) {
        
        echo '<span class="awrap"><a class="buyit" href="'. $value .'" target="_blank">Get It Here</a></span>';
        
        }
    }
    

    Thank you!

    April 25, 2018 at 4:20 am #219254
    Brad Dalton
    Participant

    Wrap the code in 1 hook and conditional.

    Use a test site to do this if you want to learn custom coding.

    I use flywheel local.


    Tutorials for StudioPress Themes.

    April 25, 2018 at 8:00 pm #219285
    ashleymichelle
    Member

    Could you reference or show me an example of how to do this? I'm a visual designer rather than developer, so my knowledge base is highly learn-as-I-go, and my googling skills apparently aren't showing me what I need to find.

    Many thanks!

  • 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