Wordpress shortcode not working

Dave picture Dave · Jan 27, 2011 · Viewed 15k times · Source

I built a very unique and javascript intensive theme for wordpress and now shortcodes do not work. I do not have any plugins installed, so it's not that. What did I drop from my wordpress template files that is required to use shortcodes (ie: [gallery]).

I understand how to make shortcodes, but how does WP take your post and replace "[gallery]" when it is spitting it back out for display?

EDIT: here is what I'm currently working with:

    $pagepull = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'page' AND post_status = 'publish' ORDER BY menu_order", ARRAY_A);
    $i = 1;
    foreach ($pagepull as $single_page){
     echo "<div class=\"section\"><ul><li class=\"sub\" id=\"" . $i  . "\"><div class=\"insection\">";
         echo $single_page['post_content'];
$i++;
// more code that is irrelevant...
// more code that is irrelevant...
// more code that is irrelevant...
    }

Answer

keatch picture keatch · Jan 27, 2011

Ok, try this

 $pagepull = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'page' AND post_status = 'publish' ORDER BY menu_order", ARRAY_A);
    $i = 1;
    foreach ($pagepull as $single_page){
     echo "<div class=\"section\"><ul><li class=\"sub\" id=\"" . $i  . "\"><div class=\"insection\">";
         echo apply_filters('the_content',$single_page['post_content']);
$i++;

Wordpress take your content and apply filters to it. You must register a filter and let parse your content.

If your theme is not displaying your shortcodes, probabily you output the content of the post without let Wordpress filter it.

Calling the function get_the_content() for a post, does not run the filter for shortcodes (if any).

To have apply

<?php apply_filters('the_content',get_the_content( $more_link_text, $stripteaser, $more_file )) ?>

Ref: http://codex.wordpress.org/Function_Reference/get_the_content

Note: many plugins register filters with the content to implement shortcodes!