• 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

Custom Field for genesis_after_header

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 › Custom Field for genesis_after_header

This topic is: resolved

Tagged: custom field, Outreach Pro

  • This topic has 7 replies, 3 voices, and was last updated 9 years, 8 months ago by wildwebwest.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • September 4, 2016 at 7:39 pm #192599
    wildwebwest
    Member

    Hey friends: I'm trying to use custom fields that seem like would be fairly straightforward.

    This code is now located in my function.php file:

    //* Hook mbr custom shortcode content after header
    add_action('genesis_after_header', 'mbr_after_header');
    function mbr_after_header() {
    if ( is_singular( 'post' ) )
    $cf = get_post_meta( $post_id, 'mbr_customfield', true );
    if(empty($cf)) {
    echo "Empty Customfield";
    } else {
    echo "".$cf."";
    }
    }

    My goal is to use the mbr_customfield name to place a unique slider revolution shortcode in the value so that a unique custom slider resolves "after_header" for each page.

    So I thought maybe the shortcode was the problem. I replaced the slider revolution shortcode with plain text for testing.

    You'll see on this page: http://87a.b45.myftpupload.com/backcountry-wedding-destination/ that my hook code at the top right under the header, is echoing "Empty Customfield" but should be echoing whats in the mbr_customfield value which is; Full Width Slider Revolution Shortcode after header will go here

    I'm not sure if this is the appropriate portal to get some help, but if someone can steer me into the right direction, I'd like to be able to use custom fields to accommodate custom sliders "after_header" for each page in this upgrade. It would be really sweet. Just got to correct the code above because its not echoing whats in that field.

    After I figure that out, I'll want to replace plain text with rev slider shortcode so if some other snippet is necessary, I"ll open a separate support thread.

    Thanks much for anyone who can help me out.

    Kind regards, mary

    Full Width Slider Revolution Shortcode after header will go here


    Wild Web West, LLC
    #IHeartGenesis

    http://87a.b45.myftpupload.com/backcountry-wedding-destination/
    September 5, 2016 at 5:44 am #192610
    Victor Font
    Moderator

    Where are you retrieving post ID? get_post_meta is designed to retrieve custom fields within the WordPress loop. To display a custom field outside of the loop, you have to do something a little different:

    /* Hook mbr custom shortcode content after header
    add_action('genesis_after_header', 'mbr_after_header');
    function mbr_after_header() {
        global $wp_query;
        $post_id = $wp_query->post->ID;
        if ( is_singular( 'post' ) ) {
            $cf = get_post_meta( $post_id, 'mbr_customfield', true );
            if(empty($cf)) {
                echo "Empty Customfield";
            } else {
                echo "".$cf."";
            }
            wp_reset_query();
        }
    }

    Even though you are echoing the shortcode, it may be get displayed as text and the shortcode may not actually execute. You should probably execute the shortcode in do_shortcode($cf).


    Regards,

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

    September 5, 2016 at 6:48 am #192619
    Brad Dalton
    Participant

    To output custom field values outside the loop, I would use get_the_ID() like this:

    add_action('genesis_after_header', 'slider_after_header');
    function slider_after_header() {
      
        if ( is_singular( 'post' ) ) {
        $cf = get_post_meta( get_the_ID(), 'slider', true );
        echo do_shortcode( $cf );
          }
    }
    

    Rather than the global variable.

    Or

    Store the id as a variable:

    add_action('genesis_after_header', 'slider_after_header');
    function slider_after_header() {
      
        if ( is_singular( 'post' ) ) {
        $postid = get_the_ID(); 
        $cf = get_post_meta( $postid, 'slider', true );
        echo do_shortcode( $cf );
          }
    }
    

    This solution is tested and works.


    Tutorials for StudioPress Themes.

    September 5, 2016 at 6:59 am #192620
    Brad Dalton
    Participant

    Global variables

    Global $post variable


    Tutorials for StudioPress Themes.

    September 5, 2016 at 8:46 am #192629
    wildwebwest
    Member

    Dear Brad and Victor,

    Thank you sooooo much for your assistance with this slightly advanced custom fields issue I was having. I can't thank you enough.

    Due to shorter code, I did end up using Brads first iteration which worked like a charm. I figured shorter code, faster results. But all three examples are so helpful in learning and skill enhancements.

    I'm flying with the geese!

    Have a wonderful day and again, muchos gracias, domo arigato, THANK YOU!!!

    Mary


    Wild Web West, LLC
    #IHeartGenesis

    September 5, 2016 at 9:02 am #192632
    wildwebwest
    Member

    Oooh. One more question.

    Brad, I would like to be able to use that custom field for both posts AND pages.

    The code works perfectly on my post at http://87a.b45.myftpupload.com/making-wedding-memories-at-mackay-bar-ranch/

    But is not calling the full width slider shortcode on a 'page' like here: http://87a.b45.myftpupload.com/hunting/

    Any suggestions?


    Wild Web West, LLC
    #IHeartGenesis

    September 5, 2016 at 9:11 am #192634
    Brad Dalton
    Participant

    Change the conditional to work with pages

     
    if ( is_singular(array(  'post', 'page'  ) ) ) {
    

    Tutorials for StudioPress Themes.

    September 5, 2016 at 9:22 am #192636
    wildwebwest
    Member

    Bravo! Thank you so much Brad! You are awesome! That worked and once again, I can't thank you enough for your excellence and willingness to help other wordpress users!

    Kind regards,

    Mary


    Wild Web West, LLC
    #IHeartGenesis

  • Author
    Posts
Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘Custom Field for genesis_after_header’ is closed to new replies.

CTA

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

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 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