Forums Forums Search & Filter Pro Add shortcodes into admin dashboard widgets

Viewing 6 posts - 1 through 6 (of 6 total)
  • Anonymous
    #95697

    Hello.
    I’m trying to add shortcodes into a dashboard widget using do_shortcode function.
    Unfortunately it doesn’t work.
    Where am I wrong?
    Thanks

    Andrea

    Trevor
    #95745

    Which dashboard widget? Is this part of a theme that you have? What code are you using please post here inside code tags (from the editor toolbar)?

    Trevor
    #95751

    Ross tells/reminds me you can’t see the toolbar. The shortcut to go before and after code is the little tick (on my keyboard it is the key to the left of the 1/! key).

    Anonymous
    #95763

    Dear Trevor,
    the widget is part of a plugin that I wrote.
    Here is the code.

    Shortcode definition:

    function search_func( ) {
       echo do_shortcode('[searchandfilter id=1067]' );
     }
     add_shortcode( 'test_search', 'search_func' );

    Admin dashboard widget definition:

    add_action( 'wp_dashboard_setup', 'register_my_dashboard_widget' );
    function register_my_dashboard_widget() {
      wp_add_dashboard_widget(
        'my_dashboard_widget',
        'My Dashboard Widget',
        'my_dashboard_widget_display'
      );
    }
    
    function my_dashboard_widget_display() {
       echo do_shortcode('[test_search]');
    }

    This code just prints “[searchandfilter id=1067]” string into “My Dashboard Widget” widget.
    It doesn’t show the content of search filter. Why?
    Is it possible to do so?

    Hope this helps.
    Andrea

    Trevor
    #95795

    The plugin does not work that way, our shortcodes do not work in Admin, only in the front end.

    Trevor
    #95797

    Normally, either you would add our widget to a sidebar, or add the shortcode to a page or post, or if the theme has content widgets (in a layout editor for example), those too usually accept the shortcode.

Viewing 6 posts - 1 through 6 (of 6 total)