Support » Fixing WordPress » Howto: Add category selection to QuickPress

  • Hi all, figured i’d share something i’ve managed to do and i’ve not seen anyone else yet document, and it is somewhat of a hack, but it does work.

    I thought about writing a blog entry about this, but felt since i spend more time here, and this site is far more active, that it would make more sense to post it here directly…

    I’m sure alot of users want to use QuickPress but still have the ability to select a category for the entries being made. Of course this only covers adding one category, but i decided the option to select one over no selection at all might be of interest to someone.

    Here’s how it’s done.

    Add the following to your theme’s functions.php file:

    function __quickpress_cats() {
    	if(!function_exists('is_admin') || !is_admin()) return;
    	// Parameters for wp_dropdown_categories
    	$args = array(
    		'order' => 'ASC',
    		'hierarchical' => 1,
    		'echo' => 0,
    		'name' => 'post_category[]',
    		'hide_empty' => 0
    	$select_cats = wp_dropdown_categories( $args );
    	echo '
    	<h4 id="category-label"><label for="post_category">Category</label></h4>
    	<div class="hide-if-no-js" style="margin: 0 0 .5em 5em;padding:8px 10px 5px 5px;">
    if(is_admin() || $query->is_admin) {
    	$here = array( basename($_SERVER['REQUEST_URI']), basename($_SERVER['SCRIPT_FILENAME']) );
    	if( ( $here[0] == ('index.php' || 'wp-admin')) && ( $here[1] == 'index.php') ) {

    The code below the function makes a basic check to see what page you’re on, so as to not hook onto the media-buttons in other places..

    Yes it’s a little hacky, and may not be rocket science, but it does function and give you the ability to choose a category when making QuickPress posts…

    Enjoy!.. 🙂

Viewing 15 replies - 1 through 15 (of 16 total)
  • great hack, but there’s a bug.

    after you submit, you get a fresh, empty quickpress screen. except this time, there’s no category picker.


    Hi johnywhy,

    I’ve actually found a better way to do this, it’s much more reliable and works for dual category selection to (if you don’t mind a few lines of jQuery in addition). There’s no way to unregister widgets from the dashboard (at present), however there is a way to unset or set data in the widget/metabox array that deals with what’s shown on the dashboard.

    Importantly this means i can change the callback function for quickpress, or in other words i can update the QuickPress widget to call my own function in place of the default function..

    I’ll post something up over the next few days.. It’ll improve on the above code somewhat.. 🙂



    Hi t31os,

    Have you figured out how to get this to work better? I’m setting up a PMU installation for our school and find that this would be the easiest way for my teachers to be able to post about two different grades on one installation. I also have that same problem as johnywhy. Any help you could give would be appreciated.




    i think i read somewhere that 3.0 might include this?

    Yes, sorry guys, was writing a plugin that included this, but ditched the plugin (got bored with it and started something else), i’ll wrap something up for you to use though as i did say i would..

    I don’t believe 3.0 includes this, or at least it doesn’t yet. I’m running 3.0 nightly on the local install, and there’s no extra category selection on the quickpress widget thus far….

    Give me a few hours and i’ll post something up for you.

    Create a file, call it what you want, for example “quickpress-category.php”…

    Place it into your plugins folder (inside it’s own folder if you like, it’ll work either way), and then add the following code.

    Save the file, load the plugins list up, and activate the plugin.

    After you do that, go to Settings > Writing , and check the box for “Enable quickpress category selection.” and click Save.

    Now once you load the dashboard you’ll see there’s an additional category dropdown box.

    Does nothing more, and nothing less… 🙂



    It works perfectly like it should when you first log in and write your first post. After pushing publish the category box disappears. Same problem as adding that code in the function file. I believe after you push the publish button it goes to the part of the dashboard.php

    function wp_dashboard_quick_press() {
    	$drafts = false;
    	if ( 'post' === strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['action'] ) && 0 === strpos( $_POST['action'], 'post-quickpress' ) && (int) $_POST['post_ID'] ) {
    		$view = get_permalink( $_POST['post_ID'] );
    		$edit = esc_url( get_edit_post_link( $_POST['post_ID'] ) );
    		if ( 'post-quickpress-publish' == $_POST['action'] ) {
    			if ( current_user_can('publish_posts') )
    				printf( '<div class="message"><p>' . __( 'Post Published. <a href="%s">View post</a> | <a href="%s">Edit post</a>' ) . '</p></div>', esc_url( $view ), $edit );
    				printf( '<div class="message"><p>' . __( 'Post submitted. <a href="%s">Preview post</a> | <a href="%s">Edit post</a>' ) . '</p></div>', esc_url( add_query_arg( 'preview', 1, $view ) ), $edit );
    		} else {
    			printf( '<div class="message"><p>' . __( 'Draft Saved. <a href="%s">Preview post</a> | <a href="%s">Edit post</a>' ) . '</p></div>', esc_url( add_query_arg( 'preview', 1, $view ) ), $edit );
    			$drafts_query = new WP_Query( array(
    				'post_type' => 'post',
    				'post_status' => 'draft',
    				'author' => $GLOBALS['current_user']->ID,
    				'posts_per_page' => 1,
    				'orderby' => 'modified'

    I’m not sure exactly where it will pull up a different part of the file to make that disappear.

    The reason that happens is because post.php calls up the old function after publish (via include, for the ajax), thus loading the original non-category enabled function, at least until the dashboard page is loaded again.

    There aren’t any hooks for me to stop this happening, i can only suggest reloading the dashboard page when this happens.



    Cool t31os_! Will be testing your code this weekend. I had disabled QuickPres in WP and WPMU dashboards because users kept forgetting to add the categories in Write panel, grrrr 🙂



    Thank you very much for all of your effort. I’m going to set it up this way for now. I’ll have my users use it like this for a while, then I’ll look through the code and see if there is anything that I can find that might be able to work without making it disappear. Maybe I can find something in there. Who knows, it might not be possible at all. I think this would be a very nice feature for them to implement in future releases of wordpress.

    You’ve really saved me users a lot of headache. If you’re ever in Taipei let me buy you a cup of coffee!

    Happy to help guys.

    Physman not sure i’m ever likely to be in Taipei, but should i be i’d welcome a good coffee, thanx.. 😉

    Let me know if you find any problems (aside from the one discussed), hopefully you shouldn’t it’s basically a copy of the original widget, with some minor additions.

    Good call. I’d love this functionality but couldn’t get this link to work:

    Is it still around or available in some other form?


    I’m glad you replied, it’s prompted a reminder for me to a submit a ticket at some point to add a small change to the code involved with this widget.

    Glad you were able to find it, although you can always just plonk the address in google and use the “cached” link to see the cached version.. 😉 Just an FYI.. 🙂

    The newer version doesn’t appear to work in 3.0 beta. The older code from the first post does, though.

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Howto: Add category selection to QuickPress’ is closed to new replies.