How to render shortcodes in WordPress templates

in Code Write a comment

In this tutorial, you’ll learn how to execute WordPress shortcodes in templates.

As you may know, WordPress shortcodes won’t execute if you just copy and paste them in .php templates directly.

[map]

You need to pass them to do_shortcode function first.


Hi, I'm Renat 👋

 


E.g. if you’re trying to display a map in a template you can do this. Replace the word ‘map’ with your own shortcode and paste the code below into your file.

<?php echo do_shortcode( '[map]' ); ?>

That’s it, it will now execute your shortcode in WordPress template file.

If you find this post useful, please let me know in the comments below. 
Cheers,
Renat Galyamov

Want to share this with your friends?
👉renatello.com/wordpress-template-shortcodes

PS: make sure you check other WordPress tutorials, e.g. Split functions.php into multiple files in WordPressload Google Fonts via functions.php in WordPress and download my plugin that improves your WordPress SEO & Performance.

A collection of UI components for
Bootstrap 4/5 and Vue.js

Get now

Write a Comment

Comment