Shortcode giving headers already sent message
-
I have a shortcode used to display posts from a certain custom post type. Initially the shortcode output was showing above the_content and with some googling I found that I needed to use the ob_start, ob_end, etc. This made it show where I wanted it, wherever in my post. However, I now get the following error message and am not sure how to fix it:
Warning: Cannot modify header information – headers already sent by (output started at /home/myaccount/wp-content/themes/mythemename/includes/shortcodes/shortcode-posts.php:47) in /home/myaccount/wp/wp-includes/pluggable.php on line 876This is the shortcode php:
<?php function mythemename_posts( $atts, $content = null) { extract(shortcode_atts(array( 'post_type' => 'posttypename' ), $atts)); $args = array( 'post_type' => $post_type, 'showposts' => -1 ); ob_start(); ?> <?php $custom_loop = new WP_Query( $args ); if ( $custom_loop->have_posts() ) : ?> <ul> <?php while( $custom_loop->have_posts() ) : $custom_loop->the_post(); ?> <li> <a href="<?php the_permalink(); ?>"> <?php if ( has_post_thumbnail()) : // Check if Thumbnail exists ?> <?php the_post_thumbnail(); // Fullsize image for the single post ?> <span></span> <?php else: ?> <span class="no-photo"></span> <?php endif; ?> <?php the_title(); ?> </a> </li> <?php endwhile; ?> </ul> <?php endif; ?> <?php wp_reset_query(); ?> <?php $output_string = ob_get_contents(); ?> <?php ob_end_clean(); ?> <?php return $output_string; ?> <?php } ?> <?php add_shortcode('listposts', 'mythemename_posts'); ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Shortcode giving headers already sent message’ is closed to new replies.