How To Remove WordPress Version From Head And Feeds
Using the following snippet, you will be able to remove WordPress version from head and feeds.
1 2 3 4 |
function complete_version_removal() { return ''; } add_filter('the_generator', 'complete_version_removal'); |
Snippet Source/Credit: Snipplr
How To List All Available WordPress Roles
Using the following snippet, you will be able to list all available WordPress roles.
1 2 3 4 5 6 7 |
$roles_obj = new WP_Roles(); $roles_names_array = $roles_obj->get_names(); echo '<select name="role">'; foreach ($roles_names_array as $role_name) { echo '<option>'.$role_name.'</option>'; } echo '</select>'; |
Snippet Source/Credit: WPSnipp
How To Have A Featured Image Before You Can Publish Post In WordPress
Using the following snippet, you will be able to have a featured image before you can publish post in WordPress.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
add_action('save_post', 'wpds_check_thumbnail'); add_action('admin_notices', 'wpds_thumbnail_error'); function wpds_check_thumbnail($post_id) { // change to any custom post type if(get_post_type($post_id) != 'post') return; if ( !has_post_thumbnail( $post_id ) ) { // set a transient to show the users an admin message set_transient( "has_post_thumbnail", "no" ); // unhook this function so it doesn't loop infinitely remove_action('save_post', 'wpds_check_thumbnail'); // update the post set it to draft wp_update_post(array('ID' => $post_id, 'post_status' => 'draft')); add_action('save_post', 'wpds_check_thumbnail'); } else { delete_transient( "has_post_thumbnail" ); } } function wpds_thumbnail_error() { // check if the transient is set, and display the error message if ( get_transient( "has_post_thumbnail" ) == "no" ) { echo "<div id='message' class='error'><p><strong>You must select Featured Image. Your Post is saved but it can not be published.</strong></p></div>"; delete_transient( "has_post_thumbnail" ); } } |
Snippet Source/Credit: WPDevSnippets
How To Customize Comment Count Text In WordPress
Using the following snippet, you will be able to customize comment count text in WordPress.
1 2 3 |
<?php echo get_comments_number_text( "No comments, yet", "One Lonely Comment", "% Happy Comments"); ?> |
Snippet Source/Credit: WPSnipp
How To Display Posts In Random Order In WordPress
Using the following snippet, you will be able to display posts in random order in WordPress.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
session_start(); add_filter( 'posts_orderby', 'randomise_with_pagination' ); function randomise_with_pagination( $orderby ) { if( is_front_page() ) { // Reset seed on load of initial archive page if( ! get_query_var( 'paged' ) || get_query_var( 'paged' ) == 0 || get_query_var( 'paged' ) == 1 ) { if( isset( $_SESSION['seed'] ) ) { unset( $_SESSION['seed'] ); } } // Get seed from session variable if it exists $seed = false; if( isset( $_SESSION['seed'] ) ) { $seed = $_SESSION['seed']; } // Set new seed if none exists if ( ! $seed ) { $seed = rand(); $_SESSION['seed'] = $seed; } // Update ORDER BY clause to use seed $orderby = 'RAND(' . $seed . ')'; } return $orderby; } |
Snippet Source/Credit: Snipplr