WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to remove "Protected" from pw protected page titles (7 posts)

  1. syncbox
    Member
    Posted 4 years ago #

    When you password protect a page in 2.8.5 and the user enters the password, the title changes to prepend "Protected:" to the actual title.

    How do you stop that behavior? Help appreciated!

  2. syncbox
    Member
    Posted 4 years ago #

    Nevermind, found my own answer (again).

    It's in the "get_the_title() functions in the post-template.php file in wp-includes, line 113 in version 2.8.5

    $protected_title_format = apply_filters('protected_title_format', __('Protected: %s'));

  3. bluepixeldesign
    Member
    Posted 4 years ago #

    But doesn't it get reset every time you update WordPress?

    I saw a fix for something else where you added code to the functions.php file in your theme so this doesn't happen. Anyone know what that code might be?

  4. bluepixeldesign
    Member
    Posted 4 years ago #

  5. jbcal
    Member
    Posted 3 years ago #

    Hi. The information on wprecipes.com states:

    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');

    I am not understanding where to put the add_filter('the_title', 'the_title_trim');

    Copying and pasting throws an error on my site, but when I remove that last line, the error is not thrown, but the "Protected" is still visible, so it obviously needs to be included.

    Any insight on this is greatly appreciated.

    Thanks,
    John

  6. pixeloco
    Member
    Posted 3 years ago #

    I posted the above code at the very top of my functions.php file and it successfully removed "Protected:" from my post titles... but I got a bunch of errors in my backend (in the post/page editors and whatnot). Placing the code elsewhere in my functions file just gave me an error and wouldn't load my site.

    Solution that worked for me:

    add_filter('protected_title_format', 'blank');
    function blank($title) {
           return '%s';
    }

    Copy and paste that code snippet at the top of your functions file... (after <?php )

    Hope that helps!

  7. jbcal
    Member
    Posted 3 years ago #

    Thanks stacybird! That did it.

Topic Closed

This topic has been closed to new replies.

About this Topic