• I have the following function that outputs HTML Content

    function featured_props_output( $atts ){  	$attr = shortcode_atts( array(		'post_type' => 'featured_props'	), $atts );    $props = get_posts([      'post_type' => $attr['post_type'],      'post_status' => 'publish',      'numberposts' => -1,      'order'    => 'ASC'    ]);  	global $post;    ob_start();  	?>  <style>  	p:empty {display:none;}  </style>      <div class="props-container">      <?php      if ( $props ) {        $even = true;          foreach ( $props as $post ) :               setup_postdata( $post );               $prop_meta = get_post_meta( get_the_ID() );               if($even){              ?>                <div class="prop-item">                    <div class="prop-cover">                      <?php echo the_post_thumbnail(); ?>                        <div class="wp-block-button" style="text-align:center;">                            <a target="_BLANK" class="wp-block-button__link" href="<?php echo $prop_meta['url'][0]; ?>">Visit Website</a>                        </div>                    </div>                    <div class="prop-desc">                        <h4><?php the_title(); ?></h4>                        <p><?php echo $prop_meta['cust_content'][0]; ?></p>                        <div class="wp-block-button" style="text-align:center;">                            <a target="_BLANK" class="wp-block-button__link" href="<?php echo $prop_meta['url'][0]; ?>">Visit Website</a>                        </div>                    </div>                </div>                <?php }else{ ?>                    <div class="prop-item">                        <div class="prop-desc">                            <h4><?php the_title(); ?></h4>                            <p><?php echo $prop_meta['cust_content'][0]; ?></p>                            <div class="wp-block-button" style="text-align:center;">                                <a target="_BLANK" class="wp-block-button__link" href="<?php echo $prop_meta['url'][0]; ?>">Visit Website</a>                            </div>                        </div>                        <div class="prop-cover">                          <?php echo the_post_thumbnail(); ?>                            <div class="wp-block-button" style="text-align:center;">                                <a target="_BLANK" class="wp-block-button__link" href="<?php echo $prop_meta['url'][0]; ?>">Visit Website</a>                            </div>                        </div>                    </div>                <?php        }        $even = !$even;          endforeach;          wp_reset_postdata();      } ?>    </div>  <?php	return ob_get_clean();}add_shortcode( 'props_output', 'featured_props_output');

    You can look at the website front-end and see that within the content is many empty p tags. Specifically after the last .prop-item, within the .prop-item, .prop-item .prop-cover, and .prop-item .prop-desc .

    I have hidden these empty p tags in CSS, but I’m wondering if there is something incorrect that I’m doing that is causing wpautop filter to add these empty p tags.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Can you reformat your PHP code for your shortcode so that we can read it more easily?

    Thread Starter devonator

    (@devoantor)

    @greenshady Thank you for bringing that to my attention; I didn’t realize the code block just put everything on one line. I cannot edit my post at this point, so I will paste the code below:

    <?php
    function featured_props_output( $atts ){
      	$attr = shortcode_atts( array(
    		'post_type' => 'featured_props'
    	), $atts );
        $props = get_posts([
          'post_type' => $attr['post_type'],
          'post_status' => 'publish',
          'numberposts' => -1,
          'order'    => 'ASC'
        ]);
      	global $post;
        ob_start();
      	?>
      <style>
      	p:empty {display:none;}
      </style>
          <div class="props-container">
          <?php
          if ( $props ) {
            $even = true;
              foreach ( $props as $post ) : 
                  setup_postdata( $post ); 
                  $prop_meta = get_post_meta( get_the_ID() ); 
                  if($even){
                  ?>
                    <div class="prop-item">
                        <div class="prop-cover">
                          <?php echo the_post_thumbnail(); ?>
                            <div class="wp-block-button" style="text-align:center;">
                                <a target="_BLANK" class="wp-block-button__link" href="<?php echo $prop_meta['url'][0]; ?>">Visit Website</a>
                            </div>
                        </div>
                        <div class="prop-desc">
                            <h4><?php the_title(); ?></h4>
                            <p><?php echo $prop_meta['cust_content'][0]; ?></p>
                            <div class="wp-block-button" style="text-align:center;">
                                <a target="_BLANK" class="wp-block-button__link" href="<?php echo $prop_meta['url'][0]; ?>">Visit Website</a>
                            </div>
                        </div>
                    </div>
                    <?php }else{ ?>
                        <div class="prop-item">
                            <div class="prop-desc">
                                <h4><?php the_title(); ?></h4>
                                <p><?php echo $prop_meta['cust_content'][0]; ?></p>
                                <div class="wp-block-button" style="text-align:center;">
                                    <a target="_BLANK" class="wp-block-button__link" href="<?php echo $prop_meta['url'][0]; ?>">Visit Website</a>
                                </div>
                            </div>
                            <div class="prop-cover">
                              <?php echo the_post_thumbnail(); ?>
                                <div class="wp-block-button" style="text-align:center;">
                                    <a target="_BLANK" class="wp-block-button__link" href="<?php echo $prop_meta['url'][0]; ?>">Visit Website</a>
                                </div>
                            </div>
                        </div>      
              <?php
            }
            $even = !$even;
              endforeach;
              wp_reset_postdata();
          } ?>
        </div>
      <?php
    	return ob_get_clean();
    }
    
    add_shortcode( 'props_output', 'featured_props_output');
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wpautop Putting Empty P tags in custom shortcode content output’ is closed to new replies.