• 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

can't get shortcodes in functions.php to work

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 › can't get shortcodes in functions.php to work

This topic is: not resolved

Tagged: Custom fields, do_shortcode, shortcode

  • This topic has 9 replies, 3 voices, and was last updated 8 years, 3 months ago by Brad Dalton.
Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • March 22, 2017 at 8:17 am #203650
    jlknauff
    Member

    I'm stuck...this outputs the shortcode text rather than the rendered result. What am I doing wrong?

    function practice_area_people() {
        if ( is_page( 'antitrust-trade-regulation' ) ) {
    		echo '<div class="practice-area-people">';
    		genesis_custom_field('antitrust-trade-regulation-people');
    		echo '</div>';
        }
    }
    add_action( 'genesis_entry_footer', 'practice_area_people' );
    March 22, 2017 at 8:59 am #203654
    Brad Dalton
    Participant

    Got stuck on this sometime ago myself and fixed it using this solution.


    Tutorials for StudioPress Themes.

    March 22, 2017 at 9:08 am #203657
    Victor Font
    Moderator

    Is the value of the antitrust-trade-regulation-people custom field a shortcode? If so, wrap the custom field output in do_shortcode().


    Regards,

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

    March 22, 2017 at 9:21 am #203658
    jlknauff
    Member

    Brad, nope...I've tried using do_shortcode as well with no luck. Even modified to use your example with no success.

    function practice_area_people() {
        if ( is_page( 'antitrust-trade-regulation' ) ) {
    		echo '<div class="practice-area-people">';
    		$custom_field = genesis_custom_field('antitrust-trade-regulation-people');
    		if ( $custom_field ) {
    			echo do_shortcode( $custom_field );
    		}
    		echo '</div>';
        }
    }
    add_action( 'genesis_before_content', 'practice_area_people' );
    March 22, 2017 at 9:24 am #203661
    jlknauff
    Member

    Hey Victor, that's one of the things I've been trying, but no dice.

    March 22, 2017 at 9:32 am #203665
    jlknauff
    Member

    Here's the odd thing...

    I'm using a shortcode that I know works for testing. (CF7)

    This simply prints the shortcode on the screen:

    $custom_field = genesis_custom_field('antitrust-trade-regulation-people');
    echo do_shortcode( $custom_field );

    However, this outputs the results:

    $custom_field = genesis_custom_field('antitrust-trade-regulation-people');
    echo do_shortcode( '[contact-form-7 id="1667" title="Contact form 1"]' );

    Does that make any sense?

    March 22, 2017 at 9:37 am #203666
    Victor Font
    Moderator

    Try genesis_get_custom_field instead of genesis_custom_field. The first returns the value of the field. The second writes it to HTML. It could be the difference.

    I also suggest using the Kint debugger so you can see the values returned in the function. https://wordpress.org/plugins/kint-php-debugger/


    Regards,

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

    March 22, 2017 at 9:47 am #203668
    Brad Dalton
    Participant

    Yes, genesis_get_custom_field is the correct function for genesis which is why your code isn't working.

    I think its also better to use get_post_meta


    Tutorials for StudioPress Themes.

    March 22, 2017 at 10:09 am #203671
    jlknauff
    Member

    When I use

        if ( is_page( 'antitrust-trade-regulation' ) ) {
    		echo '<div class="practice-area-people">';
    		$custom_field = genesis_get_custom_field('antitrust-trade-regulation-people');
    		echo do_shortcode( $custom_field );
    		echo '</div>';
        }

    it returns nothing. 🙁

    I've also tried:

    echo do_shortcode( get_post_meta( 223, $key = 'antitrust-trade-regulation-people', $single = true ) );

    which also returns no results.

    March 22, 2017 at 10:46 am #203673
    Brad Dalton
    Participant

    This works

    add_action( 'genesis_entry_footer', 'genesis_custom_field_with_shortcode' );
    function genesis_custom_field_with_shortcode() {
    $custom_field = genesis_get_custom_field('antitrust-trade-regulation-people');
    if ( $custom_field ) {
    echo do_shortcode( $custom_field );
        }
    }
    

    Assumes you have created a custom field named antitrust-trade-regulation-people and added your shortcode to the value field for that key.


    Tutorials for StudioPress Themes.

  • Author
    Posts
Viewing 10 posts - 1 through 10 (of 10 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