Tuesday, June 15, 2010

Wordpress Custom Shortcodes

I have been playing with Wordpress custom shortcodes for a template we're building here at work. Unfortunately I was having some problems getting the shortcodes to be parsed. I found out the problem in the comments of the smashing magazine article below.

SHORTCODES are only parsed when using the_content() to display the page data.

This was a problem as I was pulling the page data into a variable and then echoing $page->post_content. No worries. Once I added the loop code around the page
if (have_posts()) : while (have_posts()) : the_post();
and
endwhile; endif;
the_content() AND my short codes worked fine!

Hurray! Wordpress can be a pain, but this was easy!

Links:
http://www.smashingmagazine.com/2009/02/02/mastering-wordpress-shortcodes/
http://codex.wordpress.org/Shortcode_API
http://themocracy.com/2010/03/a-flickr-badge-using-wordpress-shortcodes/

No comments:

Post a Comment