How to use “menu_order” field for posts?

Apparently it’s as easy as: add_action( ‘admin_init’, ‘posts_order_wpse_91866’ ); function posts_order_wpse_91866() { add_post_type_support( ‘post’, ‘page-attributes’ ); } And then doing the query: $order_posts = new WP_Query(array( ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘orderby’ => ‘menu_order’, ‘order’ => ‘ASC’, ) );

adding custom stylesheet to wp-admin

According to WordPress Codex (here): admin_enqueue_scripts is the first action hooked into the admin scripts actions. Example Loading a CSS or JS files for all admin area: //from functions.php //First solution : one file //If you’re using a child theme you could use: // get_stylesheet_directory_uri() instead of get_template_directory_uri() add_action( ‘admin_enqueue_scripts’, ‘load_admin_style’ ); function load_admin_style() { … Read more

Adding Fields to the Category, Tag and Custom Taxonomy Edit Screen in the WordPress Admin?

I added new field ‘picture’ (input type file) to category with help of these add_action(‘category_edit_form_fields’,’category_edit_form_fields’); add_action(‘category_edit_form’, ‘category_edit_form’); add_action(‘category_add_form_fields’,’category_edit_form_fields’); add_action(‘category_add_form’,’category_edit_form’); function category_edit_form() { ?> <script type=”text/javascript”> jQuery(document).ready(function(){ jQuery(‘#edittag’).attr( “enctype”, “multipart/form-data” ).attr( “encoding”, “multipart/form-data” ); }); </script> <?php } function category_edit_form_fields () { ?> <tr class=”form-field”> <th valign=”top” scope=”row”> <label for=”catpic”><?php _e(‘Picture of the category’, ”); ?></label> … Read more

Adding custom columns to custom post types

The hooks to create custom columns and their associated data for a custom post type are manage_{$post_type}_posts_columns and manage_{$post_type}_posts_custom_column respectively, where {$post_type} is the name of the custom post type. This example from the documentation removes the author column and adds a taxonomy and meta data column: // Add the custom columns to the book … Read more

Changing Admin Menu Labels

Here’s the process to change the labels (I changed posts to “contacts” in my example) function change_post_menu_label() { global $menu; global $submenu; $menu[5][0] = ‘Contacts’; $submenu[‘edit.php’][5][0] = ‘Contacts’; $submenu[‘edit.php’][10][0] = ‘Add Contacts’; $submenu[‘edit.php’][15][0] = ‘Status’; // Change name for categories $submenu[‘edit.php’][16][0] = ‘Labels’; // Change name for tags echo ”; } function change_post_object_label() { global … Read more

How do I Enqueue styles/scripts on Certain /wp-admin Pages?

add_menu_page and add_submenu_page both return the page’s “hook suffix”, which can be used to identify the page with certain hooks. As such, you can use that suffix in combination with the variable hooks admin_print_styles-{$hook_suffix} and admin_print_scripts-{$hook_suffix} to specifically target these pages. function my_menu() { $menu = add_menu_page( ‘Page 1’, ‘bar’, ‘something’, ‘else’, ‘foo’ ); $submenu … Read more

How to check if a user is in a specific role?

If you only need this for current user current_user_can() accepts both roles and capabilities. UPDATE: Passing a role name to current_user_can() is no longer guaranteed to work correctly (see #22624). Instead, you may wish to check user role: $user = wp_get_current_user(); if ( in_array( ‘author’, (array) $user->roles ) ) { //The user has the “author” … Read more