4

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.

  • Because I have some widget area's specific to some templates, and would like to be able to have the interface elements in one page. I've looked into the ACF source, and a few blogs. So adding stuff to the pages is obviously possible, but I can't find a way to take a piece of the WP admin and include it elsewhere. – Jasper Kennis Apr 10 '14 at 13:17
  • I see no point in posting code here tho, this is purely a theoretical question, I don't have any code to back it up with. – Jasper Kennis Apr 10 '14 at 13:18
  • I do agree though, I wish this was a feature. If my client wants specific content on a specific pages sidebar, I have to 2 options, generate a sidebar for all pages or have the client call me to create a page specific widget area. THEN they have to leave the Pages section and go to Widgets which just seems like a run around. – Howdy_McGee Apr 10 '14 at 13:43
  • Have you not tried plugins such as widget visibility? 1 sidebar, lots of widgets that display on certain conditions – Tom J Nowell Apr 16 '14 at 14:52
  • That's not what I'm after, but you're not the only one to misunderstand. I've tried to clarify the question a little. – Jasper Kennis Apr 17 '14 at 6:57
2
+100

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.

  • Dirty, but working, lol. +1 – Pieter Goosen Apr 19 '14 at 8:28
1

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.

  • Oooh, as far as I understood it that was only for the dashboard widgets. Great, I'll be able to test this after the weekend, but I think this might be the answer I'm looking for:) – Jasper Kennis Apr 11 '14 at 14:35
  • Hm, turns out it's not really what I was looking for. Instead, I need the add_meta_box logic. Now I only need a way to show content of the widget admin part inside a meta box. – Jasper Kennis Apr 15 '14 at 14:58
  • Perhaps you should try the Advanced Custom Fields plugin. This gives you all sorts of possibilities to create extra fields in your pages (with or without meta boxes). One that we like to make is an (optional) sidebar text area. You can make this a conditionally-shown element that, if filled-in, will override any of your default widgets. Would that satisfy your above needs? – Monkey Puzzle Apr 16 '14 at 6:13
  • No, that's not it, I want to show the widgets adding and removing interface inside a meta box, basically. – Jasper Kennis Apr 16 '14 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.