Archived topic
Widget shortcode in functions.php not working
7 replies · Started by jasmeet on June 28, 2019
Hello,
I had been adding the code suggested here - https://digwp.com/2010/04/call-widget-with-shortcode/ to call widget with shortcode on guternberg block however after entering the code snippet in functions.php file of child theme, it's returning with error as shown on screenshot - https://cl.ly/b6d100ec8f34
Can you assist with the same
Regards
Hi there,
have you added the same function more than once to your functions file? If so the functions both have the same name which is the problem.
If you're looking at creating multiple shortcodes for widgets then this plugin will make that super easy:
Hi David
Thanks for the reply
1) Have reviewed once again however, I could see the functions code snippet once. Could it be that the similar code is existing somewhere else - maybe, in parent theme files etc as I am working through functions.php in child theme
2) Thanks for the suggestion. Had been using this plugin extensively, however this doesn't work for some widgets.
Example - Instead of actual widget output, It is returning with this error although the widget has already been added as per steps outlined by the specific widget developer instructions. https://cl.ly/6d5d25897513
Will appreciate for any troubleshooting steps or workaround here :)
That error states that you're redeclaring a widget function on line 109 - which has already been declared on line 16. So it has to be some code in your child theme functions that is causing the problem.
The plugin error also looks to be related to the code you're adding - you can see that very error is within the shortcode function itself. You can see it on this line:
return '<p>'.sprintf(__("%s: Widget class not found. Make sure this widget exists and the class name is correct"),'<strong>'.$class.'</strong>').'</p>';
I would test by disabling your child theme function file or at least removing any shortcode/widet related code and then retry the plugin
For troubleshooting purposes, I had disabled child theme and enabled parent theme and the shortcode for widget reflected fine..
Can you let me know the exact code snippet which can be added in functions.php file of child theme in order for specific shortcode being added to reflect fine
Where do you currently have the Shortcode Function added? In the Code Snippets plugin?
To replicate, You may install this plugin - https://wordpress.org/plugins/widget-shortcode/ to generate widget shortcode and thereafter, add the shortcode in hooks output area and similar error shall appear instead of actual output with child theme assigned!
If you're using the widget shortcode plugin then you can remove all instances of the code you got from here:
https://digwp.com/2010/04/call-widget-with-shortcode/
It is that code that is displaying that error.