Shortcode in a shortcode in a widget
-
I need to put a shortcode in a shortcode in a widget. To be exact I need this in a widget:
[wpv-view name=”Bookmaker – Payment Type List View” sapymttype =”[types field=”deposit-withdrawal”][/types]”]
However the shortcode inside the shortcode is not shown properly, and this is shown at the end where the shortcode is being incorrectly truncated: [/types]”]
This works in the main content, but in the widget it doesn’t.
I added this to funtions.php to originally make the shortcode work in the widget:
add_filter( ‘widget_text’, ‘do_shortcode’);
Many thanks for any help…
-
What widget?
just a normal text widget…
You could try changing the priority on your
add_filter
, something likeadd_filter( 'widget_text', 'do_shortcode', 1);
. Maybe that will work, but you may have a fundamental conflict with the widget code itself. If so, you will need to create your own widget.Thanks… I tried that, then I realised that if I remove add_filter( ‘widget_text’, ‘do_shortcode’); from functions file completely the shortcode still works exactly the same!
Unfortunately I only know enough to be dangerous, so I am not sure where to look next to try and get this working!
Copy the text widget shortcode from wp-includes/default-widgets.php. It is a PHP class named ‘WP_Widget_Text’. The whole declaration is ‘class WP_Widget_Text extends WP_Widget’. Copy the whole thing to your theme’s functions.php and give it a new name by changing the ‘WP_Widget_Text’ part only, so that you have, for example, ‘class My_Custom_Text_Widget extends WP_Widget’. Now edit the ‘widget’ function inside that class. Just before
$text = apply_filters...
you want to put$text = do_shortcode($text);
Now putregister_widget('My_Custom_Text_Widget');
underneath the whole ‘My_Custom_Text_Widget’ class. That is, after the closing ‘}’ of that that class.
- The topic ‘Shortcode in a shortcode in a widget’ is closed to new replies.