wpautop breaking sprintf() output in a shortcode
-
Hi everyone,
I have a plugin that generates an accordion (using Zurb Foundation framework) using shortcodes. The essential output should be:
<ul class="accordion"> <li class="accordion-item"> <a href="#" class="accordion-title"><h3>Accordion item title</h3></a> <div class="accordion-content">The content</div> </li> </ul>The code to output the title is the issue. The relevant part is:
$accordion_title = sprintf('<a id="%3$s" class="accordion-title" role="tab" tabindex="0"><h3>%2$s</h3></a>',This works perfectly fine if I use a <span> not a <h3>, but for semantic and SEO reasons I need the title to be a heading.
In functions.php I have the following code to clean up the <p> tags from shortcodes:
// Remove wpautop from wherever it is remove_filter('the_content', 'wpautop'); remove_filter('term_description', 'wpautop'); // Add it pack at priority 99 add_filter('the_content', 'wpautop', 99); add_filter('term_description', 'wpautop', 99); // Run shortcode_unautop after wpautop add_filter('the_content', 'shortcode_unautop', 100); add_filter('term_description', 'shortcode_unautop', 100);This works great everywhere except the accordion title. If I keep wpautop on, the
<a>tag has an extra<p>tag output after it with the link in it again but empty (so essentially the link is there twice but only one has text in it and works). It works fine with wpautop off, but I need wpautop everywhere else so turning it off isn’t a solution.I also tried putting the
<h3>before the<a>, not inside it, but then the<a>just gets wrapped in a<p>which stops the accordion from working.How can I stop these extra
<p>tags from being generated?Thank you so much for your time!
The topic ‘wpautop breaking sprintf() output in a shortcode’ is closed to new replies.