WordPress.org

Ready to get started?Download WordPress

Forums

The Bootstrap
Prevent shortcode being wrapped in pre div tag by default (4 posts)

  1. stemie
    Member
    Posted 11 months ago #

    I've added some custom shortcode in my functions.php but when I insert the shortcode on the page it wraps the resulting output in <pre> tags which results in undesired styling.
    I just want the shortcode to display without these tags being automatically included. How can do this?

    Thanks

  2. stemie
    Member
    Posted 11 months ago #

    I forgot to add there are no <pre> tags in the function I added, it appears to be automatically generated by the theme.

    Here is the function Im using

    function myLoop($atts, $content = null) {
    	extract(shortcode_atts(array(
    		"pagination" => 'true',
    		"query" => '',
    		"category" => '',
    	), $atts));
    	global $wp_query,$paged,$post;
    	$temp = $wp_query;
    	$wp_query= null;
    	$wp_query = new WP_Query();
    	if($pagination == 'true'){
    		$query .= '&paged='.$paged;
    	}
    	if(!empty($category)){
    		$query .= '&category_name='.$category;
    	}
    	if(!empty($query)){
    		$query .= $query;
    	}
    	$wp_query->query($query);
    	ob_start();
    	?>
    
    	<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
    		<h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php echo the_title(); ?></a></h3>
    		<?php the_excerpt(); ?>
    	<?php endwhile; ?>
    
    	<?php if(pagination == 'true'){ ?>
    	<div class="navigation">
    	  <div class="alignleft"><?php previous_posts_link('« Previous') ?></div>
    	  <div class="alignright"><?php next_posts_link('More »') ?></div>
    	</div>
    	<?php } ?>
    	<?php $wp_query = null; $wp_query = $temp;
    	$content = ob_get_contents();
    	ob_end_clean();
    	return $content;
    }
    add_shortcode("loop", "myLoop");
  3. KrisPomphrey
    Member
    Posted 10 months ago #

    I have the same problem with shortcode output being wrapped in <pre> tags.

    Shouldn't it be assumed we are wrapping our own content and give us greater control?

  4. stemie
    Member
    Posted 10 months ago #

    Such a great theme, any chance anyone can help with this problem? Please...

Reply

You must log in to post.

About this Theme

About this Topic