Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress shortcode not working

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...
    }
like image 717
Dave Avatar asked Dec 12 '22 16:12

Dave


2 Answers

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!

like image 156
keatch Avatar answered Jan 02 '23 06:01

keatch


My solution was replacing

<?= get_the_content() ?>

with

<?= the_content() ?>

which, as keatch already mentioned, applies filters before returning content.

Read this carefully about the_content

like image 33
jazkat Avatar answered Jan 02 '23 04:01

jazkat