I’ve solved this using a function. Incase some else needs this I’m posting it here below. Add it to your functions.php it will remove the unwanted <p> </p> and leftover </p> tag in de sidebar instead of the content.
function fannshop_remove_unwanted_p_tags($content) {
? ? // Remove closing </p> tags that appear right before </li>
? ? $content = preg_replace('/<\/label><\/p>/', '</label>', $content);
? ? // Remove opening <p> tags that appear right before <span class="wpf_item_count">
? ? $content = preg_replace('/<p>\s*(<span class="wpf_item_count">)/', '$1', $content);
? ? // Remove closing </p> tags that appear right after </span>
? ? $content = preg_replace('/(<\/span>)\s*<\/p>/', '$1', $content);
? ? return $content;
}
function buffer_start() {
? ? ob_start('remove_unwanted_p_tags');
}
function buffer_end() {
? ? ob_end_flush();
}
// Hook into the template rendering
add_action('wp_head', 'buffer_start');
add_action('wp_footer', 'buffer_end');