pro2go Designs Blog

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

Bookmark and Share

Related posts:

  1. How to automatically remove the Nofollow from your posts Copy the following code, and paste it on the functions.php...
  2. WordPress hack: Remove admin name in comments class This code simply have to be pasted in your functions.php...
  3. How to display custom post types on your WordPress blog homepage The following code have to be pasted in your functions.php...
  4. How to programatically remove WordPress dashboard widgets Simply paste the following into your functions.php file. The code...
  5. 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.

10 Responses to “How to remove “private” and “protected” from the post title”

  1. 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.

    DELETE a,b,c
    FROM wp_posts a
    WHERE a.post_type = 'revision'
    LEFT JOIN wp_term_relationships b
    ON (a.ID = b.object_id)
    LEFT JOIN wp_postmeta c ON (a.ID = c.post_id);
    

    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

  2. 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!

    <?php
    /*
    Plugin Name: Block Bad Queries
    Plugin URI: http://perishablepress.com/press/2009/12/22/protect-wordpress-against-malicious-url-requests/
    Description: Protect WordPress Against Malicious URL Requests
    Author URI: http://perishablepress.com/
    Author: Perishable Press
    Version: 1.0
    */
    global $user_ID; if($user_ID) {
      if(!current_user_can('level_10')) {
        if (strlen($_SERVER['REQUEST_URI']) > 255 ||
          strpos($_SERVER['REQUEST_URI'], "eval(") ||
          strpos($_SERVER['REQUEST_URI'], "CONCAT") ||
          strpos($_SERVER['REQUEST_URI'], "UNION+SELECT") ||
          strpos($_SERVER['REQUEST_URI'], "base64")) {
            @header("HTTP/1.1 414 Request-URI Too Long");
    	@header("Status: 414 Request-URI Too Long");
    	@header("Connection: Close");
    	@exit;
        }
      }
    }
    ?>
    

    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

  3. 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:

    [pdf href="http://yoursite.com/linktoyour/file.pdf"]View PDF[/pdf]

    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

  4. 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

  5. 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

  6. 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

  7. 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

  8. 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

  9. 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

  10. 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

Leave a Reply

Special Thanks: St. Pete Air Conditioning, Kissimmee Florida Auto Repair and Sales, African Safari Vacation, and Medical Practice Broker