Sort custom post types by last name in the backend

If you want to override the default- and the title ordering, and order instead by the last word in the title. /** * Override default- and title ordering in the backend, for the ‘speaker’ custom post type. * * @link https://wordpress.stackexchange.com/a/202154/26350 */ add_action( ‘pre_get_posts’, function( \WP_Query $q ) { if ( is_admin() && $q->is_main_query() && … Read more

How do you modify CSS files via admin panel?

If you’re wanting styles to be dynamic, then you’ll have to emit your CSS file as you are suggesting. However, as WordPress often uses styles.css as a theme definition file, renaming styles.php might cause problems. It might be better to collect all the ‘dynamic’ definitions into a separate file (eg dynamic-styles.php) and import them from … Read more

500 Internal Server Error after Register dialog, but with successful registration

Internal Server errors are usually thrown when there’s an error somewhere in the code. You did the right thing searching the logs, but depending on your hosting configuration not all errors can be written there. I like using WordPress’s own logging facility. Here’s what you need to do: Stick the following lines in your wp-config.php … Read more

WordPress 3.8 get current admin color scheme

I actually made it! In my script file, at the to I define a new variable and copy the $_wp_admin_css_colors variable into it using the admin_head hook, since the variable gets destroyed at some later point: <?php global $admin_colors; // only needed if colors must be available in classes add_action(‘admin_head’, function() { global $_wp_admin_css_colors; global … Read more

How to Change the Title of a Meta Box on a Specified Custom Post Type? [duplicate]

Yes – you need a slightly modified version of this answer. add_action( ‘add_meta_boxes_post’, ‘wpse39446_add_meta_boxes’ ); function wpse39446_add_meta_boxes( $post ) { if( ‘mycpt’ == get_post_type($post) ){ remove_meta_box( ‘authordiv’, ‘mycpt’, ‘core’ ); add_meta_box( ‘authordiv’, __(‘Team Member’,’wpse39446_domain’), ‘post_author_meta_box’, ‘mycpt’, ‘advanced’, ‘high’ ); } } Note: If you are doing this for a non-core metabox, you’ll need to ensure … Read more

How to securely add an Ajax button to a WP Admin page?

In this answer I created 2 buttons which are visually disabled and get an invalid nonce before submitting. <?php /* Plugin Name: Ajax Example */ add_action( ‘admin_notices’, ‘my_action_button’ ); define( ‘MY_ACTION_NONCE’, ‘my-action-‘ ); function my_action_button() { $id = 4321; $data = array( ‘data-nonce’ => wp_create_nonce( MY_ACTION_NONCE . $id ), ‘data-id’ => $id, ); echo get_submit_button( … Read more