We build a media (based on bootstrap 4 media object) shortcode with the following syntax:
[media img="https://via.placeholder.com/64x64.png"]<h5>List-based media object</h5>Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis. Fusce condimentum nunc ac nisi vulputate fringilla. Donec lacinia congue felis in faucibus.[/media]
The function can be found here:
add_shortcode( 'media', 'xcore_shortcode_media' );
/**
* Media shortcode
*
* @doc https://getbootstrap.com/docs/4.3/components/media-object/
*
* @param $atts
* @param null $content
*
* @return string
*/
function xcore_shortcode_media( $atts, $content = null ) {
extract(
shortcode_atts(
array(
'style' => 'primary',
'class' => '',
'img' => '',
'align' => '',
'order' => 'left'
),
$atts
)
);
// vars
$style = ( $atts['style'] ? $atts['style'] : 'primary' );
$class = ( $atts['class'] ? $atts['class'] : '' );
$img = ( $atts['img'] ? $atts['img'] : '' );
$align = ( $atts['align'] ? $atts['align'] : '' );
$order = ( $atts['order'] ? $atts['order'] : 'left' );
$attributes = array(
'class' => array( 'xcore-media', 'media' ),
);
if ( $style ) {
$attributes['class'][] = 'media-' . $style;
}
if ( $class ) {
$attributes['class'][] = $class;
}
if ( $img ) {
$img_classes = array();
if ( $order == 'left' ) {
$img_classes[] = 'mr-3';
} else {
$img_classes[] = 'ml-3';
}
if ( $align ) {
$img_classes[] = 'align-' . $align;
}
$img_html="<img src="" . $img . '" class="' . implode ( ' ', $img_classes ) . '"/>';
}
$output="<div " . xcore_attribute_array_html( $attributes ) . '>';
if ( $order == 'left' ) {
$output .= $img_html;
}
$output .= '<div class="media-body">';
$output .= do_shortcode( $content );
$output .= '</div>';
if ( $order == 'right' ) {
$output .= $img_html;
}
$output .= '</div>';
return $output;
}
The Problem:
WordPress puts an empty p-Tag right before the headline. When we start without a headline in our content, it works fine.
Here a example:
Is there any way to remove this without deactivate the auto p function completely?
Thanks