Hi,
First, thanks for the nice plugins and features.
I’d like my widget titles to have anchor made of the first word of the title.
In the former version of SO Page Builder, I had tweaked default.php – I know it’s a bad habit to change the code of a plugin, but I needed it quick.
Obviously, the tweak went away with the update.
So I dug a bit deeper : I looked for a filter I could hook to.
There’s the generic WP ‘widget_title’ and there’s a SO filter called ‘siteorigin_panels_widget_args’ which gets passed an array with before_title and after_title.
I figured I could insert an anchor tag (
<h3 id="title") into before_title. But I needed my hook to know the widget’s title.
So I added just this one line in siteorigin-panels.php :
function siteorigin_panels_the_widget() { // line 1243 (...) $title_html = siteorigin_panels_setting( 'title-html' ); // line 1271 if( strpos($title_html, '{{title}}') !== false ) { list( $before_title, $after_title ) = explode( '{{title}}', $title_html, 2 ); } else { $before_title = '<h3 class="widget-title">'; $after_title = '</h3>'; } $args = array( 'before_widget' => '<div class="' . esc_attr( implode( ' ', $classes ) ) . '" id="' . $id . '" data-index="' . $widget_info['widget_index'] . '">', 'after_widget' => '</div>', 'before_title' => $before_title, 'after_title' => $after_title, 'widget_id' => 'widget-' . $grid . '-' . $cell . '-' . $panel, 'title' => $instance["title"] // line added ! ); // Let other themes and plugins change the arguments that go to the widget class. $args = apply_filters('siteorigin_panels_widget_args', $args); (...) }
I added a hook in my theme’s functions.php, and it works just fine.
But I suppose that it will break again on the next update.
So here are my two questions :
is this method correct ? (and if not what would you recommend ?)
do you think this change in siteorigin-panels.php could make its way to the next version ?
Thanks,
Emmanuel
Hi Emmanuel,
I like this idea, but I’m not too sure on doing it exactly like this. Hm, I think using the widget_title filter would be better. I’m going to log this as PR for PB 3.0 for testing.
Hi Alex,
Thanks for your answer.
Following your advice, I’ve been trying with the widget_title filter, but I can’t get it to work.
It seems my hook is ignored or the title is overwritten after my hook, whatever the priority I set :
That should make all titles on all pages ‘foobar’, shouldn’t it ? Well nothing happens…
Am I missing something obvious ?
Hi Manumie,
Oh, sorry – that wasn’t a suggestion in terms of how you should do it but how we should allow it. I should have been clearer. You’ll need to stick with your current method for the time being, sorry mate. :(
To clarify, widget_title is only used in a few specific instances at the moment and I’ve logged a PR to change it so it’s used on every widget title in Page Builder (if it’s set up in the standard manner).
Ok, thanks !