I want to turn this off as I have a custom ordering process using custom fields.
5 Answers
You can't turn it off, because it's hard-coded into the submit metabox for the post post type, you can however hide the sticky checkbox and update the sticky array to unstick any currently stuck posts.
Hide the sticky checkbox
Add additional CSS to the post and post-new pages
add_action( 'admin_print_styles', 'hide_sticky_option' );
function hide_sticky_option() {
global $post_type, $pagenow;
if( 'post.php' != $pagenow && 'post-new.php' != $pagenow )
return;
?>
<style type="text/css">#sticky-span { display:none!important }</style>
<?php
}
Unstick any currently stuck posts
Add this one of your theme files, load a page that calls that file, then remove
update_option( 'sticky_posts', array() );
Hope that helps. :)
Your code was really helpful for me, but the "sticky post" option is still showing on the quick edit at the "All posts" page, so I've made some changes to fix this:
// 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
}
// Unsticky all posts
update_option( 'sticky_posts', array() );
-
Can you please add an explanation, so that someone who doesn't have the knowledge can learn from your answer - thanks. Commented Jul 10, 2014 at 20:42
-
@ialocin — In lieu of an updated answer, basically: 1. Add the following function to those run during the "admin_print_styles" hook (which inserts CSS et al) 2. Expose the current page global 3. Stop processing function if not on a page with the sticky post toggles in question 4. Otherwise append some CSS that hides said-toggles.– aendraCommented Aug 24, 2015 at 11:41
None of the CSS hacks worked for me, because each editor can have a number of <div class='componenets-panel__row'></div>
and since stick to top checkbox doesn't have a defining class like the most of the components-panel__row
elements, the best way is to drill down to the label and remove the parent element with some JavaScript.
This code works 100% and it's ugly.
/**
* Hide sticky post option
*/
function remove_sticky_checkbox_admin_js() {
$script =
"window.addEventListener('load', (event) => {
const panelRows = document.querySelectorAll('.components-panel__row');
[].forEach.call(panelRows, function (e) {
console.log(e.childNodes);
[].forEach.call(e.childNodes, function (ev) {
if(ev.tagName === 'DIV') {
[].forEach.call(ev.childNodes, function (eve) {
if(eve.tagName === 'DIV') {
[].forEach.call(ev.childNodes, function (even) {
if(even.tagName === 'DIV') {
[].forEach.call(even.childNodes, function (event) {
if(event.tagName === 'LABEL' && event.innerText === 'Stick to the top of the blog'){
e.remove();
}
});
}
});
}
});
}
});
});
});
";
echo '"<script type="text/javascript">'. $script . '</script>"';
}
add_action('admin_footer', 'remove_sticky_checkbox_admin_js');
Add the code below to hide the sticky checkbox when you are on the edit or the add new post page in the WP admin. It will rehide the sticky checkbox when switching between blocks. This only works for the Gutenberg Editor.
/**
* Hides the Sticky Checkbox on the Post Edit/ Add New Post screen
*
* @return void
*/
function hide_admin_sticky_checkbox(): void {
?>
<script>
function hideAdminStickyCheckbox() {
// Grab all labels
let labels = jQuery('.components-panel label.components-checkbox-control__label');
labels.each(function(){
let label = jQuery(this);
if ( label.html() == 'Stick to the top of the blog') {
// We found the label
// Hide with jQuery
label.closest('.components-panel__row').hide();
// Stop
return;
}
});
}
// Run when the DOM changes for that panel
jQuery('body').on('DOMNodeInserted', '.edit-post-sidebar .edit-post-post-status', hideAdminStickyCheckbox);
</script>
<?php
}
add_action('admin_footer-post.php', 'hide_admin_sticky_checkbox', 999, 0);
add_action('admin_footer-post-new.php', 'hide_admin_sticky_checkbox', 999, 0);
Here is the CSS I used to hide it in WordPress 6:
.edit-post-post-schedule +.components-panel__row {
display: none;
}