
What I’ve always thought would be a neat plugin would be something that gave users the ability to insert WordPress template tags from within the Write Post/Page screen. I’ve also gotten a few requests for this type of functionality.
Template Tag Shortcodes comes loaded with 40 shortcodes that represent their equivalent template tags.
For example, a commonly used template tag is wp_list_pages(). But, it’s a PHP function and can’t be used within the post editor (without a PHP plugin). With this plugin, you could simply type in [wp_list_pages] and let the plugin do all the work.
The available shortcodes
If you know me, you know I can’t stop at one or two shortcodes. That’s why I made 40.
Several shortcodes have additional parameters, which are listed in the plugin’s readme.html file. Here’s the list of what’s currently available in the plugin.
[wp_list_authors][the_author][the_author_description][the_author_login][the_author_firstname][the_author_lastname][the_author_nickname][the_author_ID][the_author_url][the_author_email][the_author_link][the_author_aim][the_author_yim][the_author_posts][the_author_posts_link][the_modified_author][wp_list_categories][wp_dropdown_categories][the_category][get_category_link][the_date][the_time][the_modified_date][the_modified_time][wp_tag_cloud][the_tags][get_tag_link][wp_list_bookmarks][the_title][the_title_attribute][the_ID][the_permalink][get_permalink][wp_list_pages][wp_dropdown_pages][wp_get_archives][bloginfo][allowed_tags][wp_logout_url][wp_login_url][comments_link][category_description][tag_description][term_description][the_terms][the_author_meta]
I’m sure more will be added over time. If you have a particular template tag you’d like to see as a shortcode, just let me know in the comments.
Some important notes
These shortcodes don’t provide additional XHTML formatting. For example, [wp_list_pages] won’t be wrapped with the <ul> tag. This is because its equivalent template tag wp_list_pages() does not do this. So, you’ll want to add any additional formatting from within the post editor.
I struggled with this decision but thought it was the best route. The goal was to adhere to the same rules as the WordPress template tags.
Download the Template Tag Shortcodes plugin
Get the plugin. Enjoy. Let me know how it works out for you. For full instructions, see the readme.html file included with the plugin download.
- Version: 0.1.1
- Requires: WordPress 2.5+
- Support: Support forums
- Download (WP.org plugin repository)
Please don’t use my contact page or the comments section below to ask support questions. Use my support forums at Theme Hybrid, which is where I handle all support questions for my WordPress projects.
If you run across any bugs or want to share ideas about how to make this plugin better, feel free to post in the comments below.
That is a really awesome idea for a plugin! I’m for sure going to grab this and give it a run!
If only the plugin created a UI element to allow easy insertion while posting so users wont have to remember the format of a template tag
The Frosty — Thanks. I had a few requests and figured it’d be useful. It wasn’t too tough to throw together.
African Boy — Remind me to never, ever add a UI for this plugin.
Sorry, I’m just a firm believer that we should start taking things out of the admin instead of putting more things in.
nice plugin for designers.
Will it parse attributes too? things like [wp_tag_cloud number="10"] to get ten tags? That would be great. And do the shortcodes work in text widgets too (which would effectively make them a sort of meta-widgets)? Love it btw, brilliant idea.
Short codes are way too cool. You made my day
Thanks Justin !
Awesome plugin Justin, and great question Roy, I’m anxious to know the answer.
topcool — I’m thinking it should be nice for Average Joe, but I suppose even designers can use it.
Roy Tanck — The
readme.htmlfile shows the various parameters you can input for each shortcode. Not all shortcodes have them. But, shortcodes that do have parameters replicate their equivalent template tag.As for shortcodes in widgets, that’s something this plugin shouldn’t control. See this tutorial on making shortcodes work in widgets.
I haven’t tested all of the parameters because that would take forever. I figured I’d let you all do that and let me know what works and what doesn’t.
Many — You’re welcome. I like shortcodes too, at least when I have a bunch of them packaged together.
Adam W. Warner — Thanks. See my answer to Roy.
This is a super-cool Sauron-style plugin (1 shortcode plugin to rule them all!), Justin. Does
[the_author_email]useantispambot()?Ian Stewart — It doesn’t currently use
antispambot(), but I’m thinking it might be a good idea to make that change in the next version. There’s really no reason for it not to.Another awesome plugin Justin. I’ve always had trouble turning over a site to a client, where I used php in a post or page with the runPHP plugin, then they go to edit that post with the visual editor and it gets all messed up and stops working. I’ve written a few small plugins for myself and found a few others to replace a couple specific needs I had (wp_list_pages being one, to list child pages on a parent page) but this is really awesome. I am going to see if I can stop using the runPHP plugin altogether and just use this instead.
Thanks very much.
I’ve just installed this plugin, no problems or anything. Really useful. Can’t wait for more shortcodes!
Chris Hajer — I have that same problem, except I’m the one always screwing things up on my own site. I usually just code a quick shortcode in my theme anytime I have some PHP that I’m reusing on multiple pages. It’s the easiest way to steer clear of future headaches.
If I can help you get rid of any more PHP template tags, let me know what they are. I’ll be happy to add more to the plugin.
Danny — Glad to hear everything’s working for you.
Please please please always keep it this way:
> The goal was to adhere to the same rules as the WordPress template tags.
This is exactly how I would expect it to work. If you decide to extend the plugin, please make sure that all the base functionality of the template tags goes unchanged. After years of getting used to passing parameters to template tags, I would hate to have to unlearn that to use this awesome plugin.
Thanks again.
Great idea for a plugin Justin! If you could get this work with the_meta and custom fields, that would be amazingly awesome!!!
Awesome!
Last few days you are furfilling my plugin dreams! First cleaner gallery, widgets reloaded, widget-reset, then get-the-image (way cool), query posts and now this! I am almost exclusively using your plugins, there is no need for any else.
You are making my world better every day, thank you so much!
I am about to join exclusive hybrid theme club (at this moment I am just solving PayPal issue) and so at least a bit help you continue developing those amazing frameworks.
Thank you, man!
Chris Hajer — I plan to keep it that way. I think it is the best route.
Bryan Harley — I thought about incorporating some of the custom field stuff. Several of the custom field functions return arrays instead of strings, which is a problem when we’re dealing with a shortcode.
the_meta()is pretty much out because it prints to the screen rather than returning unless there’s aget_the_meta()equivalent.get_post_meta()would work as a shortcode if you specified to return a single value.It’s something that would come in handy, and I’d definitely love to have the functionality myself.
Mijk — Glad I could be of service. And, we’d be happy for you to join our community at Theme Hybrid.
I’d love to have that functionality too. I think it would totally revolutionize the use of custom fields!!!
Figure it out! You can do it! Heh heh.
Bryan Harley — I’ve been thinking it over a bit. What follows does not concern the
the_meta()function, which I might be able to find a solution for.The problem I see with most custom field functions is that we don’t know what to do with an
arrayof information. For example, how would it be output? The very nature of custom fields makes it impossible to predict what the user wants to do with them. This leads us back to having to use PHP within the post, which kind of goes against the idea of shortcodes.It’s easy to code the shortcodes to grab the information, but since the plugin can’t know what to do with that information, there’s not much we can do. Now, the easy part happens when you do know what to do with the information. You could easily code custom shortcodes to perform specific tasks with your custom fields.
I’m also wondering how useful it would really be. Custom fields are for attaching additional meta information about a specific post. Shortcodes are for adding information inside of a post. Wouldn’t it be easier just to add the information within the post itself? It seems like we’d be adding an additional layer of complexity.
Are there tags for comments that I’m just missing? Specifically, I’m needing comments_number().
R.A. Ray — The shortcode equivalent of
comments_number()is not currently available. All of the available shortcodes are listed above and in thereadme.html. I’ll try to add in some comment stuff in the next version.Thanks man! Love the plugin so far.
THANK YOU FOR MAKING THIS. <3 <3 <3
This was exactly what I was looking for. Thanks, a huge super big alot! hehe
thanks, this is very useful plugin for “lazier” like me, hehe…
Love the plugin! For the same reasons as people list above (letting clients edit pages without messing them up). Bravo Justin!
Feature request: The ability to NEST template tags (or use variables). IE: If I want to show the pages that are in the same parent/child relationship in a particular thread, something like
[wp_list pages [the_ID]]
I know this can be done in PHP, but it would be oh so nice to be able to do it in Template Tag Shortcodes
Thanks for this plugin Justin.
Just one question : is there any way to use [the_title] with the ID parameter? As it can be done with [get_permalink id=244] to show the permalink of one post in another one.
Thanks
Glou
This is super!
One question. [wp_list_categories] returns list items, but no enclosing or
Any suggestions of shortcodes my WYSIWYG editors could use to enclose the list.
Like [ul] [/ul] ?
Hi mate,
Is there any way to filter [wp_list_categories]?
For example I don’t need all category groups, and their sub categories. Just one group. If I could I would be using something like:
… in my code.
Thanks,
L
is it possible to insert in the future the last posts written with the function of wordpress??
Example
.aaaa
.bbb
.ccc
.ddd
5 posts recently
Ever since OZH Random Words plugin broke with 2.8, I am in desperate need of a random text plugin that works within posts.
There is Random Text by Pants on Head which is compatible with 2.8 but it only displays via widget or template tags.
Can I pay you to add shortcode functionality to Random Text by Pants on Head?http://wordpress.org/extend/plugins/randomtext/
http://www.pantsonhead.com/wordpress/randomtext/
Please email me. I really need it!
Oh, let me add, because it’s not clear in the instructions, the plug in adds random text via this template tag:
Hello!
Thanx for a plugin!!
i’m using – [wp_tag_cloud] in post (publication)
can smbd please tell how to asign a class for that code??
i see the source is:
Gillian Anderson
David Duchovny
Ken Camroux
so, in style.CSS i put
.tag-link {text-decoration:none; color:black;}
.tag-link a {text-decoration:none; color:black;}
but no result.
please help.
Nice one, would definitely come in handy.
I’ve been trying to find the opposite type of thing however, need to learn how to turn a shortcode into a template tag.
Hi Justin
Thanks for creating such a great plugin. Unfortunately, I failed to add ‘tags’ shortcode.
function tags_guwe_banget ($atts) {
global $wpdb, $post;
if (!empty($post->ID)){
$tags = implode(“,”, $atts);
wp_set_post_tags($post->ID, $tags, true);
}
//wp_set_post_tags($post->ID, $atts[0], true);
return ;
}
add_shortcode(‘tags’, ‘tags_guwe_banget’);
It works if the tag is only one single word such as php, wordpress, shortcode, or obama. But it fails when I write it this way.. [tags Barrack Obama, Michael Jackson]. It produces 4 different tags: barrack, obama, michael, and jackson. How do I make it right? Many thanks!
Hi there Justin,
Thanks for a great plugin. Would it possible to add support for more bloginfo parameters? (http://codex.wordpress.org/Function_Reference/bloginfo). Right now it defaults to “show” but it would be nice to be able to get things like description, url, template_url and so on.
Just an idea
-swex
Justin, forget what I wrote, I just found out it accepts all available parameters. My bad, remove the comment if you want
-swex
This plugin is awesome! Whew thanks! ^_^
Thanks, great plugin!
Love the plugin! I use it EVERY day!
Would it be possible to add a shortcode used by another plugin?
Right now I use your plugin to display recent posts more prominently within a post Example: http://bit.ly/ccKEQ1
I would also like to add “related” posts using the “WordPress Related Posts” plugin (http://wordpress.org/extend/plugins/wordpress-23-related-posts-plugin/)
I’m not a coder, but am comfortable adding code to a file. I don’t see a “subscribe to comments” option, so you can email me here: http://chiefscommand.com/about-chiefs-command/contact-chiefs-command/
Thanks!
Great plug-in!
Just used it on a clients website and worked like a treat!
nice work Justin
Would you consider adding support for more mundane template tags, like the_content, the_excerpt or the_post_thumbnail?
I’m not sure how much use
the_content()andthe_excerpt()would get. The purpose of shortcodes is to put them within your content, and these are content-displaying functions..the_post_thumbnail()is definitely on my to-do list though.How can I show just subcategories under a certain category or subpages under a certain parent page? Even better if there is a way to list them with bullets or numbering.
Thanks!
Just found this, what a fabulous plugin for so many uses!
Wonderful, simple and all you need. Thank you Justin.
This one’s going ‘straight to the pool room’!
Great plug-in!
nice work Justin