Community Forums › Forums › Archived Forums › General Discussion › Shortcode inside Function
Tagged: do_shortcode, function call
- This topic has 4 replies, 2 voices, and was last updated 9 years, 3 months ago by
LanceHillier.
-
AuthorPosts
-
August 5, 2017 at 7:27 pm #210031
LanceHillier
ParticipantHi 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 #210034Brad Dalton
ParticipantYou have 2 options :
1. Use
echo do_shortcode('[shortcode_tag]');Or better still
2. Use the contact forms function call.
August 6, 2017 at 2:58 am #210036LanceHillier
ParticipantThanks 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 #210037Brad Dalton
ParticipantIt 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
August 6, 2017 at 5:45 pm #210056LanceHillier
ParticipantBrad, 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. -
AuthorPosts
- The topic ‘Shortcode inside Function’ is closed to new replies.