• 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

Shortcode inside Function

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 › General Discussion › Shortcode inside Function

This topic is: resolved

Tagged: do_shortcode, function call

  • This topic has 4 replies, 2 voices, and was last updated 9 years, 3 months ago by LanceHillier.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • August 5, 2017 at 7:27 pm #210031
    LanceHillier
    Participant

    Hi All,

    I have added my content into the front-page.php file like this,

    function add_text_genesis() {
    echo 'my HTML content'
    ;
    }

    add_action('genesis_after_header', 'add_text_genesis');

    Inside the html(in the function) I have a WP contact form inside one half of a column class that sits at the bottom of the page like this..

    <div class="one-half first">
    <h5>Contact Biz Admin Solutions</h5>
    </br>

    • o Tailored bookkeeping to suit your needs
    • o Save you time, so you can focus on the bigger picture
    • o Flexibility to adapt to your needs over time
    • o Work closely with accountants and trusted advisors
    • o Provide timely and accurate reporting to help your business succeed
    • o Provide a full range of bookkeeping services using up to date software
    • o Ensure you meet your tax and financial obligations
    • o Registered BAS agent

    </div>

    <div class="one-half">

    [wpforms id="112"]

    </div>

    My Problem is I can't get the short code to work, and to be honest don't even know if short codes will work inside a function? is it possible?

    I understand the do_shortcode function and how that works in relation to php, but because this is inside html and then inside php....

    Thanks guys I usually bang my head against the brick wall until unhealthy before asking for help, and hope to one day give back, I appreciate it.

    Cheers,
    Lance.

    August 6, 2017 at 12:30 am #210034
    Brad Dalton
    Participant

    You have 2 options :

    1. Use

    echo do_shortcode('[shortcode_tag]');

    Or better still

    2. Use the contact forms function call.


    Tutorials for StudioPress Themes.

    August 6, 2017 at 2:58 am #210036
    LanceHillier
    Participant

    Thanks Brad,

    The do_shortcode won't work inside the function, and because the contact form is inside the column class I can't break the html to add the php...

    Cant seem to get it to work that way anyway, I'm probably not doing it the way its supposed to be done and might have to come at it from another angle.

    I'm not sure what the contact forms function call is, but I'll look into that now.

    Thanks for the reply mate!
    Lance.

    August 6, 2017 at 3:08 am #210037
    Brad Dalton
    Participant

    It will if coded correctly.

    echo '<div class="one-half">';
    echo do_shortcode('[shortcode_tag]');
    echo '</div>';
    

    Or like this :

    echo '<div class="one-half">' . do_shortcode('[shortcode_tag]') . '</div>';
    

    or use printf

    printf( '<div class="your-class">%s</div>', do_shortcode( '[shortcode_tag]' ) );
    

    More code examples here


    Tutorials for StudioPress Themes.

    August 6, 2017 at 5:45 pm #210056
    LanceHillier
    Participant

    Brad, Thank you!!!

    I've got it working thanks to your suggestions above, thanks for taking the time to respond, I've been on that one for a few weeks:-)

    Cheers,
    Lance.

  • Author
    Posts
Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Shortcode inside Function’ 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