skip to main content.

i stumbled over a wordpress bug making my xhtml invalid. in fact, i noticed i stumbled about it the second time. i think the first time was when i installed wordpress 3.0, and the second time after upgrading to 3.0.1. the problem is, that shortcodes which appear in single lines should not be enclosed with <p>…</p> according to the manual. but my wordpress installation is doing exactly that what is claimed to be fixed for some time.
i started digging a bit, and quickly noticed that i already fixed it. since it seems to be a persistent problem i want to document it, just in case i have it again. internally, wordpress first runs the function wpautop on the content, which adds <p>…</p>, and then runs shortcode_unautop to remove <p>…</p> around shortcodes standing in a single line. (in previous wordpress versions, both was done in wpautop if i recall correctly.) now the problem is, that my wordpress installation calls these two functions in the wrong order. so shortcode_unautop is called first, finds nothing to remove, and then wpautop is called, which adds the faulty <p>…</p> code.
an easy fix is to change wp-include/default-filters.php by changing all lines add_filter(‘whatever‘, ‘shortcode_unautop’); to add_filter(‘whatever‘, ‘shortcode_unautop’, 11);. after that, everything is fine. i wonder whether this happens on every installation or just on some.
now that i fixed this a second time, i wanted to find out in more detail what’s going on. after some digging, i found out that the cause is a plugin i use: wp_unformatted. it removes wpautop from the filter list and adds it again later, hence moving it after shortcode_unautop if both have the same default priority. well, so the right thing is to fix that plugin.
in case you want to know how to fix that plugin, proceed as follows:

  1. change the line in wp_sponge from return wpautop($pee); to return shortcode_unautop(wpautop($pee));;
  2. add remove_filter(‘the_content’, ‘shortcode_unautop’); after remove_filter(‘the_content’, ‘wpautop’);.
posted in: computer www
tags:
places:

comments.

no comments.