Admin: global $post empty

The basic mistake is, that every data is available at the point where you write your code. That isn’t the case and hooks are there to provide access to the core code during different states of the core loading procedure graph. In short and very simplified things run like this: # core loads // …more … Read more

Making menu link open in new tab?

You can do that with jQuery. We can open this link in new tab/window by adding target=”_blank” attribute dynamically on link which has URL https://www.example.com. Here is the example function for that. function wpse_my_custom_script() { ?> <script type=”text/javascript”> jQuery(document).ready( function($) { $( “ul#adminmenu a[href$=’https://www.example.com’]” ).attr( ‘target’, ‘_blank’ ); }); </script> <?php } add_action( ‘admin_head’, ‘wpse_my_custom_script’ … Read more

How to change admin menu position of “Media”?

There’s a combination of two filters, menu_order does the job, but you also use custom_menu_order to enable menu_order. function wpse_233129_custom_menu_order() { return array( ‘index.php’, ‘upload.php’ ); } add_filter( ‘custom_menu_order’, ‘__return_true’ ); add_filter( ‘menu_order’, ‘wpse_233129_custom_menu_order’ ); This will put upload.php (the Media screen) just after the Dashboard and then the other top-level menu items will follow. … Read more

How to enable enqueue_script to work with a logged in user?

Additionally, apart from the “where” of your wp_enqueue_script() function (i.e. theme, plugin, etc.), the “when” is also important, in terms of WP’s Action Reference hooks, and the order in which they’re fired. There are 2 distinct script-related hooks, wp_enqueue_scripts and admin_enqueue_scripts, which allow for separation of scripts and styles depending on which view the user … Read more

How can I change the title of an Add New page in Admin for custom post type

When you’re registering new post type with register_post_type, you can pass labels parameter (which is an array of labels used for that CPT). You can customize these labels: ‘name’ – general name for the post type, usually plural. The same and overridden by $post_type_object->label. Default is Posts/Pages ‘singular_name’ – name for one object of this … Read more

Remove the whole menu in the admin

add_action(‘admin_head’, ‘t5_hide_menu’); function t5_hide_menu() { $GLOBALS[‘menu’] = array(); ?> <style>#adminmenuback,#adminmenuwrap{display:none !important} #wpcontent, #footer{margin-left:0 !important}</style> <?php } Now I want to know: why? 🙂

Sort wp_nav_menu() by menu order

The nav_menu_items are already sorted by menu_order. When you go into the Appearance -> Menus and arrange the order menu the menu_order of each menu item gets updated. To change the orderby parameter in the query that displays the menu you can use pre_get_posts to alter it. Example: add_action( ‘pre_get_posts’, ‘wpse_sort_nav’ ); function wpse_sort_nav( $query … Read more

get user list in admin area

What you’ve done is incredibly bad practice, and should be undone immediatley. There is already a dedicated table for storing user details aka User Meta. Altering the user table could cause issues with other plugins and Core, prevent upgrades working, and bypasses all the caching and object stores WordPress puts in place. It also adds … Read more

Removing the “Popular Terms” area from the Taxonomy Edit Screen in the Admin Area

Oh, I love it when you give me an easy one. Starts to make up for all those harder ones… (well, partly. 😉 So what you want is to replace this: (source: mikeschinkel.com) With this: (source: mikeschinkel.com) How? Use the ‘wp_tag_cloud’ hook which you can put into your theme’s functions.php file or in a .php … Read more