Easy code fix: add_filter( ‘widget_text’, ‘do_shortcode’, 11 );
-
Love the plugin! A subtle detail of how you are registering the
do_shortcode
callback to thewidget_text
filter is giving me problems on all of my widgets, ones that have nothing to do with ToC+.The basic change I’m hoping for is this, in
toc.php
:// add_filter( 'widget_text', 'do_shortcode' ); add_filter( 'widget_text', 'do_shortcode', 11 );
What you’re doing with that code is just making sure that shortcodes work inside widgets, which is important and really should be default, BUT there’s a problem where if you attach it at the default priority, it ends up causing extra
<p></p>
tags to get inserted into widget content under certain circumstances.Specifically in my case, it plagues any images with captions I insert into posts, which get an extra <p> before the caption that screws up the formatting:
In fact, I’ve already been through all this in my own code, where I previously did it like you did, but then switched it to priority
11
to fix the problem.Looking through the code on my site, I found that both my own code, and the code of another big plugin, Geo Mashup, both have the “priority 11 trick” applied. But then because I had ToC+ running, it was coming back up for me.
In geo-mashup, they did a smart thing:
if ( ! has_filter( 'widget_text', 'do_shortcode' ) ) { add_filter( 'widget_text', 'do_shortcode', 11 ); }
This is great because in my case, the fact that I (and that plugin) have already defined it at 11 means that it wouldn’t have caused problems either way. Considering there’s so many plugins that enable this filter, I think doing it conditionally like this is worthwhile.
Thanks for taking a look and fixing! I think you’ll find everything works fine at priority 11, and it will likely avoid some strange problems for your users.
- The topic ‘Easy code fix: add_filter( ‘widget_text’, ‘do_shortcode’, 11 );’ is closed to new replies.