I have tried out a few things to remove the <br>
being created in between shortcodes, I found one in another thread, it looked promising, but it didn't work out:
function the_content_filter($content) {
$block = join("|",array("category_product_list", "category_products"));
$rep = preg_replace("/(<p>)?\[($block)(\s[^\]]+)?\](<\/p>|<br \/>)?/","[$2$3]",$content);
$rep = preg_replace("/(<p>)?\[\/($block)](<\/p>|<br \/>)?/","[/$2]",$rep);
return $rep;
}
add_filter("the_content", "the_content_filter");
I was reading that wpautop could do the trick but nothing is working for me. Do I need to modify my actual shortcode somehow?
Here's one of the shortcodes I'm working with:
function category_product_list( $atts ) {
extract(shortcode_atts(array(
'category' => '',
'per_page' => -1,
'orderby' => 'title',
'order' => 'asc'
), $atts));
$meta_query = WC()->query->get_meta_query();
$tax_query = WC()->query->get_tax_query();
$tax_query[] = array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( esc_attr($category) ),
'operator' => 'IN',
);
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'posts_per_page' => $per_page,
'orderby' => $orderby,
'order' => $order,
'meta_query' => $meta_query,
'tax_query' => $tax_query
);
$products = new WP_Query( $args );
if ( $products->have_posts() ) :
$term_list = wp_get_post_terms($products->post->ID, 'product_cat', array("fields" => "all"));
$first_term = $term_list[0];
$first_term_name = $first_term->name;
$url = get_permalink();
$id = $products->post->ID;
// $html_out = '<h2>Courses</h2>';
$html_out = '<ul class="simple-sitemap-courses">';
$html_out .= '<li class="page-item page-item-' . $id . '"><a href="' . $url . '">' . $first_term_name . '</a>';
$html_out .= '<ul class="children">';
while ($products->have_posts()) :
$products->the_post();
$product = get_product( $products->post->ID );
$course_title = get_the_title();
$url = get_permalink();
$id = $products->post->ID;
// Output product information here
$html_out .= '<li class="page-item page-item-' . $id . '"><a href="' . $url . '">' . $course_title . '</a></li>';
endwhile;
$html_out .= '</ul>';
$html_out .= '</li>';
$html_out .= '</ul>';
else : // No results
$html_out = "No Courses Found.";
endif;
wp_reset_postdata();
return $html_out;
}
add_shortcode( 'category_product_list', 'category_product_list' );