DZone
Web Dev Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Web Dev Zone > WordPress : Run shortcode in PHP template file

WordPress : Run shortcode in PHP template file

Sachin Khosla user avatar by
Sachin Khosla
·
Jul. 25, 11 · Web Dev Zone · Interview
Like (0)
Save
Tweet
6.85K Views

Join the DZone community and get the full member experience.

Join For Free

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.

<?php
 // Use shortcode in a PHP file (outside the post editor).
 do_shortcode('[your_own_shotcode]');
?>

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/

PHP WordPress Template

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Types of UI Design Patterns Depending on Your Idea
  • What Is HttpSession in Servlets?
  • Challenges to Designing Data Pipelines at Scale
  • Your Old Laptop Is Your New Database Server

Comments

Web Dev Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo