2

I need to create a custom WordPress admin interface for a client. I want to completely disable the sticky post feature from admin area.

I found some posts on the internet that suggest to hide the checkbox using css, but I would really like to disable that feature both from edit and from quick edit screen.

Any ideas?

1

In addition to CSS you could try to unstick each post as soon as it has been made sticky (untested):

add_action( 'post_stuck', function( $post_id )
{
    unstick_post( $post_id );
} );

If you're looking for another approach, than hiding it from the UI with CSS, then consider using custom post types instead of the post post type.

As far as I remember the sticky UI feature is only supported by the post post type. At least a quick look at the posts list table class, shows a check like this one:

if ( 'post' === $post_type && $sticky_posts = get_option( 'sticky_posts' ) ) {

But not using the post post type, might not be suitable in many cases, and it might need further adjustments for your site.

0

you could add this code:

// Hide sticky posts
add_action( 'admin_print_styles', 'hide_sticky_option' );
function hide_sticky_option() {
global $post_type, $pagenow;
if( 'post.php' != $pagenow && 'post-new.php' != $pagenow && 'edit.php' != $pagenow )
    return;
?>
<style type="text/css">#sticky-span { display:none!important }
.quick-edit-row .inline-edit-col-right div.inline-edit-col > :last-child > label.alignleft:last-child{ display:none!important; }</style>
<?php
}

This works great for me.

0

The best and most optimal solution is to simply "ignore" sticky posts on all queries which can be done with this code:

add_filter( 'pre_get_posts', function( $query ) {
    if ( ! is_admin() && $query->is_main_query() ) {
        $query->set( 'ignore_sticky_posts', 1 );
    }
} );

Of course the user can still click the checkbox but it won't actually do anything so it won't matter. But here is a good article showing how to hide with CSS if wanted - Is there a way to disable the sticky posts feature?

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.