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

Learn how Crafter’s Git-based content management system is reinventing modern digital experiences.

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/

Crafter CMS is a modern Git-based platform for building innovative websites and content-rich digital experiences. Download this white paper now.


Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}