I was recently working on my new blog, and I came across a shortcode I could use to display some content on the blog, but the problem I faced was using the shortcode in my theme file since shortcodes are special tags that you can enter into a post that gets replaced with different content when actually viewing the post on the website.
I made my research found the php function code that could easily help you echo a shortcode in a WordPress PHP theme file and decided to share it with you.
The WordPress do_shortcode() function is all you need to work this out.
Simply add the shortcode in this format.
<?php echo do_shortcode( ‘your-shortcode‘ ); ?>
All you need do is replace the blue text your-shortcode with the exact shortcode text you want to use on your blog’s theme file.
Hurray! You’ve successfully displayed your wordpress shortcode in your wordpress theme file.
11 Comments
Thought you gonna drop list of some short-codes.
Hi Nehemiah, it’s a guide to displaying WP shortcodes in your WordPress theme files. BTW, what kinda shortcode do you need and for what?
😀 nice one.
drop a shortcode list including some basic need according to you.
I don’t quite get this. Anyway, I don’t know much about coding but I think you should explain further so that your readers can fully understand this post.
Oscar,
Is this shortcode placement code you shared theme specific or actually works across board?
Always,
Terungwa
The short code should work in all themes I suppose. If it’s theme specific, Mr. Oscar would have told us.
It works across all WP themes, as in the usage of the shortcodes in wordpress theme files.
Would give it some try on my demo Wp….
Sure, it definitely does work.
How do i get my theme files.. And am nt seeing anytin lyk shortcodes in the theme templates
Where can i get my theme files?