Hong Yi
Hong Yi

Reputation: 569

Wordpress Caption Broken

I am currently learning how to make a wordpress theme but somehow the caption tag is broken. For some reason it adds quotation marks to the code and the code is being displayed on the page itself. I understand that this affected WP 3.4 and later but I have not been using any plugins etc. Can I ask what is the correct way to solve this problem? Thanks. My Wordpress version is 3.6.

Problem

This is my loop to display the posts.

 <div role="main">
<?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
<div <?php post_class(); ?>>
    <article <?php post_class(); ?>>
    <header class="post-header">
     <a class="post-header" href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a></header>
     <time class="post-date"><p> <?php the_time('l, j M Y')?></p></time>
    <p class="post-content"><?php echo get_the_content(); ?></p>
    <!-- put post class tags in -->
    <div class="tags-container">
    <?php $tags = get_the_tags();
    if( $tags ) : ?>
      <?php foreach( $tags as $tag ) { ?>
       <span class="tags <?php echo $tag->slug; ?>"><i class="icon icon-tag"></i><a href="<?php echo get_tag_link($tag->term_id); ?>"><?php echo $tag->name; ?></a></span>
      <?php } ?>
    <?php endif; ?>
    </div>      
    </article>
</div>
<?php endwhile; ?>
<?php endif; ?>

Upvotes: 0

Views: 2087

Answers (2)

This can also happen if you are custom rendering the content. Once again, not using the the_content() function.

If you can't or don't want to use the_content(), you could always wash the outputted content with the strip_shortcodes() function. Like so:

$content = $article->post_content;
$content = strip_shortcodes($content);

Upvotes: 0

Ennui
Ennui

Reputation: 10190

Replace <?php echo get_the_content(); ?> with <?php the_content(); ?>.

I believe get_the_content() returns the raw content from the DB and does not run it through the normal filters that are applied to the_content() such as wpautop and do_shortcode (although the WP Codex entry is not clear about this).

Unless you have a specific reason to use get_the_content() (like passing it into a function or filter) you should use the_content() which automatically echos the content and runs it through WP's default content filters.

If that does not solve your problem, most likely a plugin or custom theme function is preventing the shortcode from being parsed.

edit: verified that get_the_content() returns unfiltered post content. Curiously this is not directly stated in the get_the_content() function reference but instead is in the function reference for the_content() (Alternative Usage section).

Upvotes: 4

Related Questions