Skip to content

Instantly share code, notes, and snippets.

@cabrailsford
Last active July 14, 2020 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cabrailsford/78945cf3e186cf092a590def8f887658 to your computer and use it in GitHub Desktop.
Save cabrailsford/78945cf3e186cf092a590def8f887658 to your computer and use it in GitHub Desktop.
Functions to enforce showing of excerpt regardless of previous checkbox selection, and to hide the excerpt checkbox option.
<?php
// Update post to force show of excerpt
function edit_post_show_excerpt() {
$user = wp_get_current_user();
$unchecked = get_user_meta( $user->ID, 'metaboxhidden_post', true );
if( !empty( $unchecked ) ){
$key = array_search( 'postexcerpt', $unchecked );
if ( $key !== FALSE ) {
array_splice( $unchecked, $key, 1 );
update_user_meta( $user->ID, 'metaboxhidden_post', $unchecked );
}
}
}
add_action( 'admin_init', 'edit_post_show_excerpt', 10 );
// Remove checkbox to hide/unhide excerpt
function remove_post_excerpt_checkbox() { ?>
<style>
.metabox-prefs label[for="postexcerpt-hide"] {
display: none;
}
</style>
<?php }
add_action( 'admin_head', 'remove_post_excerpt_checkbox' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment