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 error monitoring with Sentry closes the gap between the product team and your customers. With Sentry, you can focus on what you do best: building and scaling software that makes your users’ lives better.

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/

What’s the best way to boost the efficiency of your product team and ship with confidence? Check out this ebook to learn how Sentry's real-time error monitoring helps developers stay in their workflow to fix bugs before the user even knows there’s a problem.


Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}