Make WordPress Core

Opened 5 years ago

Last modified 5 years ago

#49492 new defect (bug)

wpautop inserted p tags inconsistently alter visual space

Reported by: mesmer7's profile mesmer7 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.3.2
Component: Formatting Keywords:
Focuses: Cc:

Description

I wrote a custom shortcode to insert a <figure></figure> in my posts. wpautop inserts an empty <p></p> before the <figure>.

If I place the shortcode before the first paragraph after a subheading, the inserted <p> increases the visual space between the subheading and the paragraph. But if I place the shortcode before the second paragraph, the extra <p> doesn't affect the visual spacing between paragraphs.

I can work around the inconsistency by changing wpautop's priority. But that scrambles other things on the web site.

   remove_filter( 'the_content', 'wpautop' );
    add_filter('the_content', 'wpautop', 12);

add_shortcode('hd_product', 'display_product');

function display_product($args){

	extract(shortcode_atts(array(
		'id' => null,
		'cat' => null,
		'tag' => null,
		'orderby' => 'rand',
		'limit' => 1,
		), $args));


		$product = wc_get_product( $id );
		
		$image =  $product->get_image($size = 'product-slider',  ["class" => "product-callout-image","alt"=>"mp3 for sale"] );
		$term = get_term_by( 'id',  $product->category_ids[0], 'product_cat' );


		$output = '<figure class="product-callout">';		
		$output .= '<a href="' . get_permalink($id) . '">' . $image ;
		$output .= '<figcaption class="product-callout-caption"><b>' .  $term->name . '</b><br>' .  '$' . $product->price . '</figcaption>';
		$output .=   '</a></figure>';
		
		return $output;
}

Change History (1)

#1 @SergeyBiryukov
5 years ago

  • Component changed from General to Formatting
  • Summary changed from wpautop inserted p tags inconsistantly alter visual space to wpautop inserted p tags inconsistently alter visual space
Note: See TracTickets for help on using tickets.