How To Disable WordPress Comments Completely
The following snippet will let you disable WordPress comments completely.
1 |
<?php return false; ?> |
Snippet Source/Credit: aotearoawebdesign.co.nz
How To Automatically Delete Trash On Daily Basis
When you delete a post or a page or a comment, it goes in a Trash instead of being removed permanently. Using the following snippet will ease you job of deletion and will tell WordPress to automatically delete the trash itself. Simply copy and paste the following lines of code in your wp-config,php file and you are done.
1 |
define('EMPTY_TRASH_DAYS', 1); |
Note: Make sure that you do replace 1 by X to empty spam comments automatically every X days.
How To Show Content For Logged In Users
Adding this snippet to your theme’s functions.php file will let you show content only for logged in users.
1 2 3 4 5 6 7 8 9 10 |
<?php add_shortcode("hide","hide_shortcode"); function hide_shortcode($x,$text=null){ if(!is_user_logged_in()){ return "You have to been registered and logged in to see this content"; }else{ return do_shortcode($text); } } ?> |
Snippet Source/Credit: Snipplr
How To Redirect Users To A Random Post
The following snippet will let you redirect users to a random post.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
// set arguments for get_posts() $args = array( 'numberposts' => 1, 'orderby' => 'rand' ); // get a random post from the database $my_random_post = get_posts ( $args ); // process the database request through a foreach loop foreach ( $my_random_post as $post ) { // redirect the user to the random post wp_redirect ( get_permalink ( $post->ID ) ); exit; } |
Snippet Source/Credit: Smashing Magazine
How To Have Custom Favicon For Your WP-Admin
Using the following snippet, you will be able to have custom favicon for your WP-admin.
1 2 3 4 |
function admin_favicon() { echo '<link rel="shortcut icon" type="image/x-icon" href="' . get_bloginfo('template_directory') . '/images/favicon.ico" />'; } add_action( 'admin_head', 'admin_favicon' ); |
Snippet Source/Credit: Snipplr