October 22, 2013

Execute WordPress Shortcode from PHP

Published: 22 October 2013 

Sometimes when building themes, we need to execute shortcode directly from php.  This can be for things such as Forms, Sliders, Galleries etc.

Below is the code needed. Replace the code between the ‘ and ‘ marks with your own. (Few examples below).

Execute Category List
<?php echo do_shortcode('[catlist id=1 numberposts=5)]'); ?>

Execute Slidedeck Slider
<?php echo do_shortcode('[SlideDeck2 id=7]'); ?>

Execute Gravity Form
<?php echo do_shortcode('[gravityform id="1" name="Contact Me" ajax="true"]'); ?>

Execute NextGEN Gallery
<?php echo do_shortcode('[nggallery id=12]'); ?>

Ben Maden

Read more posts by Ben

Leave a Reply

Your email address will not be published. Required fields are marked *