2

By default the title column on a post/page/custom post type page in WordPress admin area is sortable.

How can I disable the sorting option?

enter image description here

I think the question is clear but just to extend it a little bit.

I am customizing the custom post types page in the admin area.

My code:

add_filter( 'manage_sponsor_posts_columns', 'kiran_set_columns' );

function kiran_set_columns( $columns ) {
    $newColumns = array();
    $newColumns['title'] = 'Sponsor';
    return $newColumns;
}

I do not want the title column to provide the sorting feature.

5

The filter hook manage_edit-post_sortable_columns contains all the columns, which are sortable. So you could hook into this filter and unset the title:

<?php

add_filter( 'manage_edit-post_sortable_columns', 'wse_240787' );
function wse_240787( $col ) {
    unset( $col['title'] );
    return $col;
}

This filter is documented in wp-admin/includes/class-wp-list-table.php:

  /**
     * Filters the list table sortable columns for a specific screen.
     *
     * The dynamic portion of the hook name, `$this->screen->id`, refers
     * to the ID of the current screen, usually a string.
     *
     * @since 3.5.0
     *
     * @param array $sortable_columns An array of sortable columns.
     */
$_sortable = apply_filters( "manage_{$this->screen->id}_sortable_columns", $sortable_columns );

Since our current screen Id is edit-post the filter is manage_edit-post_sortable_columns.

If you are using a custom post type, the screen ID would change to edit-{$cpt_slug}. For example for pages it would be edit-page. If your CPT is sponsor, it would be edit-sponsor. (Thanks @bravokeyl for pointing to this).

  • 3
    The screen for the OP might be different as that is a custom post type, so I guess it would be manage_edit-sponsor_sortable_columns. – bravokeyl Sep 28 '16 at 7:44
  • You are right, will add this to my answer! – websupporter Sep 28 '16 at 7:47
  • 1
    I didn't know that unset can be used for manage_edit-{cpt}_sortable_columns. Thanks for the help and all the info. Have a great day. – Kiran Dash Sep 28 '16 at 8:03

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.