Over a million developers have joined DZone.

WordPress : Run shortcode in PHP template file

DZone's Guide to

WordPress : Run shortcode in PHP template file

· Web Dev Zone ·
Free Resource

Bugsnag monitors application stability, so you can make data-driven decisions on whether you should be building new features, or fixing bugs. Learn more.

WordPress shortcode is very useful while creating new posts or pages. It is a nifty way to perform certain tasks in the post. For instance, if you want to add a youtube video or image gallery then WordPress shortcodes are quite useful.

Many plugins provide their own shortcodes for displaying certain content or performing some tasks. However, you might require the same plugin functionality in a theme file. Since the shortcode tag is not a standard one so you cannot write it in the PHP file. WordPress provides a wrapper function to make this shortcode work in the PHP file.

Just paste the following PHP code at the place where you want that shortcode to work.

 // Use shortcode in a PHP file (outside the post editor).

It’s an awesome way to use a shortcode inside the template files. Hope it helps.


From http://www.digimantra.com/tutorials/wordpress/wordpress-run-shortcode-php-template-file/

Monitor application stability with Bugsnag to decide if your engineering team should be building new features on your roadmap or fixing bugs to stabilize your application.Try it free.


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}