How to remove “private” and “protected” from the post title
The only thing you have to do is to paste the following piece of code in your functions.php file. Once you’ll save the file, the hack will be applied to your your posts.
function the_title_trim($title) {
$title = attribute_escape($title);
$findthese = array(
'#Protected:#',
'#Private:#'
);
$replacewith = array(
'', // What to replace "Protected:" with
'' // What to replace "Private:" with
);
$title = preg_replace($findthese, $replacewith, $title);
return $title;
}
add_filter('the_title', 'the_title_trim');
Credits goes to Chris Coyier for this awesome piece of code. Have you checked out the book Chris wrote with Jeff Starr? It’s called Digging into WordPress and it is a must-have for all WordPress fans!
Personal announcement, I’m selling the webdev.fm domain name for only $50. Just send me an email if you want it!
Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!
How to remove “private” and “protected” from the post title
![]()
View full post on WpRecipes.com
Related posts:
- How to automatically remove the Nofollow from your posts Copy the following code, and paste it on the functions.php...
- WordPress hack: Remove admin name in comments class This code simply have to be pasted in your functions.php...
- How to display custom post types on your WordPress blog homepage The following code have to be pasted in your functions.php...
- How to programatically remove WordPress dashboard widgets Simply paste the following into your functions.php file. The code...
- Use WordPress As Private Network To Promote Your Content On Social Networks Many people blog for fun while others blog to make...
Related posts brought to you by Yet Another Related Posts Plugin.

Just run the following query on your WordPress database, and all revisions (As well as meta associated with it) will be deleted from your database.
Of course, do not forget to make a backup of your database before running the code.
If you’d like to see more SQL queries for WordPress, make sure to read this post.
Thanks to One Extra Pixel for this cool query!
Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!
WordPress tip: Get rid of unused post revisions
Paste the following code into a text file, and save it as blockbadqueries.php. Once done, upload it to your wp-content/plugins directory and activate it like any other plugins. That’s all!
Thanks to Jeff Starr for this great plugin! Do you know that Digging into WordPress, Jeff’s book, has just been updated? Click here for more info.
Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!
WordPress plugin: Protect your blog from malicious URL Requests
The first step is to paste the following code into your functions.php file:
function pdflink($attr, $content) { return '<a class="pdf" href="http://docs.google.com/viewer?url=' . $attr['href'] . '">'.$content.'</a>'; } add_shortcode('pdf', 'pdflink');Once you saved the file, you’ll be able to use the shortcode on your posts and page. Here is the syntax:
Thanks to Noscope for this great shortcode!
Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!
WordPress tip: Create a PDF viewer shortcode
The first thing you have to do is to paste the following function in your functions.php file.
function switchTheme($theme) { global $wpdb; if (isset($theme)) { $queries = array("UPDATE wp_options SET option_value = 'default' WHERE option_name = 'template';", "UPDATE wp_options SET option_value = 'default' WHERE option_name = 'stylesheet';", "UPDATE wp_options SET option_value = 'default' WHERE option_name = 'current_theme';"); foreach ($queries as $query){ $wpdb->query($query); } } }What I’ve done in the function was simply to update the wp_options table (change the prefix if necessary) with a new theme name. You probably noticied that I used queries in a loop, which isn’t a good practice. There’s for sure a better way to do it but since I’m not a SQL expert I can’t get anything better. If you know how to achieve the same effect without using looped queries, don’t hesitate to leave me a comment!
Once you’ve pasted the function in your functions.php file, you can call it, for example using a filter. The $theme parameter is the theme name. For example default to restore the good old Kubrick theme.
Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!
WordPress trick: Change theme programatically
The following code have to be pasted in your functions.php file. Once the file will be saved, it will work.
As you can see in the code, the post, page, album, movie, quote, and attachment types will be displayed. Modify that line to fit your own needs.
add_filter( 'pre_get_posts', 'my_get_posts' ); function my_get_posts( $query ) { if ( is_home() ) $query->set( 'post_type', array( 'post', 'page', 'album', 'movie', 'quote', 'attachment' ) ); return $query; }Please note that custom post types are not available by default on WordPress 2.9. You could have a look there if you’re looking to implement that functionnality right now.
Credits goes to Justin Tadlock for this handy recipe!
By the way, if you’re looking to advertise on WpRecipes, I got a free spot so be quick! Click here to buy.
Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!
How to display custom post types on your WordPress blog homepage
The only thing you have to do is to paste the following piece of code in your functions.php file. Once you’ll save the file, the hack will be applied to your your posts.
function the_title_trim($title) { $title = attribute_escape($title); $findthese = array( '#Protected:#', '#Private:#' ); $replacewith = array( '', // What to replace "Protected:" with '' // What to replace "Private:" with ); $title = preg_replace($findthese, $replacewith, $title); return $title; } add_filter('the_title', 'the_title_trim');Credits goes to Chris Coyier for this awesome piece of code. Have you checked out the book Chris wrote with Jeff Starr? It’s called Digging into WordPress and it is a must-have for all WordPress fans!
Personal announcement, I’m selling the webdev.fm domain name for only $50. Just send me an email if you want it!
Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!
How to remove “private” and “protected” from the post title
Just paste the following code anywhere on WordPress theme files. If you want to test, I recommend pasting it in your functions.php file.
That’s all you have to do. Once executed, this code will insert a new post into WordPress database.
global $user_ID; $new_post = array( 'post_title' => 'My New Post', 'post_content' => 'Lorem ipsum dolor sit amet...', 'post_status' => 'publish', 'post_date' => date('Y-m-d H:i:s'), 'post_author' => $user_ID, 'post_type' => 'post', 'post_category' => array(0) ); $post_id = wp_insert_post($new_post);Thanks to Matt Harzewski for this great piece of code!
Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!
WordPress tip: Insert posts programmatically
Simply paste the following code on your functions.php file and save it. No other action is needed!
function replace_uploaded_image($image_data) { // if there is no large image : return if (!isset($image_data['sizes']['large'])) return $image_data; // paths to the uploaded image and the large image $upload_dir = wp_upload_dir(); $uploaded_image_location = $upload_dir['basedir'] . '/' .$image_data['file']; $large_image_location = $upload_dir['path'] . '/'.$image_data['sizes']['large']['file']; // delete the uploaded image unlink($uploaded_image_location); // rename the large image rename($large_image_location,$uploaded_image_location); // update image metadata and return them $image_data['width'] = $image_data['sizes']['large']['width']; $image_data['height'] = $image_data['sizes']['large']['height']; unset($image_data['sizes']['large']); return $image_data; } add_filter('wp_generate_attachment_metadata','replace_uploaded_image');Thanks to Serge Rauberfor sharing his great tip with us!
Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!
How to automatically use resized images instead of originals
Copy the following code, and paste it on the functions.php file from your theme. Once you saved the file file, the rel=”nofollow” attributes will be removed.
function remove_nofollow($string) { $string = str_ireplace(' rel="nofollow"', '', $string); return $string; } add_filter('the_content', 'remove_nofollow');Thanks to Jeff Starr for this awesome piece of code. Have you checked out the book Jeff wrote with Chris Coyier? It’s called Digging into WordPress and it is great!
Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!
How to automatically remove the Nofollow from your posts
Just paste the following into your function.php file, save it, and you’re done.
function childtheme_favicon() { ?> <link rel="shortcut icon" href="<?php echo bloginfo('stylesheet_directory') ?>/images/favicon.png" > <?php } add_action('wp_head', 'childtheme_favicon');Don’t forget to change the favicon url if needed. Also, please note that if the wp_head() function haven’t been implemented in your theme, this recipe will not work.
By the way, if you’re looking for premium WordPress themes and plugins, just have a look to the dedicated category on CouponsForBloggers.com!
Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!
Add a favicon to your WordPress blog using a hook