• 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, (add_filter…”) 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

Viewing 7 replies - 1 through 7 (of 7 total)
  • Anonymous User

    (@anonymized-3085)

    I think that '#Protected:#', should be 'Protected:', likewise for Private.

    All of the code just goes in your functions.php, including the add_filter line.

    Thread Starter jbcal

    (@jbcal)

    Hmm..I’ve tried removing the hash marks, but to no avail. I don’t get the error now, but the “Protected:” is still there.

    Just to be clear, I’m copying the entire code as it is and pasting it. Is there anything else that I am missing that would keep this from working?

    Is there another solution besides this one that will remove “Protected;” and “Private:”?

    Thanks,
    John

    Anonymous User

    (@anonymized-3085)

    Actually I just looked at the code, there may be a slightly easier way – I’ll do some tests for you and see what I come up with.

    Anonymous User

    (@anonymized-3085)

    yep even easier:

    function my_privates($text){
    	$text='My Privates: %s';
    	return $text;
    }
    add_filter('private_title_format','my_privates');

    filter for protected is similar: protected_title_format. The %s will display the title of the post/page, so is really required.

    Thread Starter jbcal

    (@jbcal)

    Thanks, Rich. I copied and pasted your code into functions.php and then went to test it. When I click Edit under the Page (so I can then view it because it’s a draft) I get the following:

    Fatal error: Call to undefined function add_filter() in .../html/g/wp-includes/functions.php on line 3816

    Any suggestions?

    Thanks again for your help!
    John

    you may have edited the wrong functions.php;
    (/wp-includes/ is one of the wordpress core folders)

    there should be a functions.php in the theme folder:

    /wp-content/themes/your_theme/functions.php

    Anonymous User

    (@anonymized-3085)

    and if your theme doesn’t have a functions.php, just create one.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Removing "Protected:" from password protected pages’ is closed to new replies.