Can I display the widget admin in the page admin?

I would like to show the ‘Appearance -> Widgets’ menu underneath the text field in ‘Pages -> new/edit’. Is it possible to take one part of the admin and show it elsewhere?

Reading some of the answers, it seems this question get’s misunderstood. I’m looking for a way to show the widgets admin on the page edit admin screen.

Related posts

Leave a Reply

2 comments

  1. If I understand well your want to show the widgets adding and removing interface inside a meta box.

    An easy, -a little dirty- way is using an iframe:

    function metaboxed_widgets_admin() {
      if ( ! current_user_can( 'edit_theme_options' ) ) return;
      add_meta_box('metaboxed_widgets', __('Widgets'), 'metaboxed_widgets_admin_cb', 'page');
    }
    add_action( 'add_meta_boxes', 'metaboxed_widgets_admin' );
    
    function metaboxed_widgets_admin_cb() {
      if ( ! current_user_can( 'edit_theme_options' ) ) return;
      $format = '<div style="margin:0px;padding:0px;">';
      $format .= '<iframe src="%s" frameborder="0" %s></iframe></div>';
      // add a query arg to recognize when inside iframe, used to hide menu and admin bar
      $url = add_query_arg(
        array( 'iframe'=> wp_create_nonce('widgets') ), admin_url( 'widgets.php' )
      );
      printf( $format, $url, 'style="height:1200px;width:100%;" height="100%" width="100%"' );
    }
    
    function metaboxed_widgets_hide_stuff() {
      if ( ! is_admin() || get_current_screen()->id !== 'widgets' ) return;  
      $iframe = filter_input( INPUT_GET, 'iframe', FILTER_SANITIZE_STRING );
      if ( wp_verify_nonce( $iframe, 'widgets' ) ) {
        echo '<style>'
        . '#wpadminbar, #adminmenuback, #adminmenuwrap, #wpfooter, '
        . '#screen-meta-links, .wrap > h2 { display:none!important; }'
        . '#wpcontent { margin-left:25px!important; }'
        . '.wrap{ margin-top:0!important; }</style>';
      }
    }
    add_action( 'admin_head-widgets.php', 'metaboxed_widgets_hide_stuff' );
    

    Note that only users who can see widgets will view the widget metabox, e.g. editors will not see anything, unless you give them the 'edit_theme_options' capability.

  2. Yes it is, and this can be a very handy feature. The ‘hiding place’ for widgets is one of the least intuitive designs of the WordPress backend, IMHO.

    You can use a plugin such as: Widgets on Pages

    Or perhaps a more up-to-date one such as Widgetize Pages

    Or you can build code yourself and place it elsewhere in the admin (such as the dashboard). A tutorial like this should help in that pursuit.

    Or you can use the legendary Advanced Custom Fields plugin and create one or more of your own optional/compulsory ‘widgets’ that can be added to any individual page.