• abhik03

    (@abhik03)


    Hey guys,
    I was writting a page which I don’t want to appear in page list.
    But when I access that page directly through the URL, a Private prefix is being added to the page’s name just above the content.
    How can I remove that?

    Thanks in advance
    Abhik

Viewing 15 replies - 1 through 15 (of 23 total)
  • baalam

    (@baalam)

    My question is similar to this one… I want to change the “Private” prefix to read something else… where can I modify this?

    agitcorp

    (@agitcorp)

    I am having the same issue. I want am creating custom pages for newsletter sign-up (successful, unsubscribe, etc) and thought the private page option would be a quick and easy way to create these pages but not have them appear in the navigation. But then the ‘Private’ prefix shows up. Would sure love to kill that. Any thoughts?

    t31os

    (@t31os)

    It’s handled by post-template.php, which is a core file…

    Line 106 – Line 118

    function get_the_title( $id = 0 ) {
    	$post = &get_post($id);
    
    	$title = $post->post_title;
    
    	if ( !is_admin() ) {
    		if ( !empty($post->post_password) )
    			$title = sprintf(__('Protected: %s'), $title);
    		else if ( isset($post->post_status) && 'private' == $post->post_status )
    			$title = sprintf(__('Private: %s'), $title);
    	}
    	return apply_filters( 'the_title', $title );
    }

    You could add a new filter, or just use a preg_replace to avoid editing the above (which would have to be done for each upgrade).

    agitcorp

    (@agitcorp)

    Thank you!

    Is it possible to update the post-template.php file in my theme and thereby avoid having the fix blown out by each upgrade?

    So I guess my question is: Is this a file that can be moved into the theme?

    t31os

    (@t31os)

    I can think of 2 ways to do it, but i’ll need to test and post back tomorrow / today, it’s time for bed shortly… 🙂

    t31os

    (@t31os)

    Ok, then…..

    Standard Function:

    <?php
    function the_title_trim($title=null)
    {
      $title = the_title('','',false);
      $pattern[0] = '/Protected:/';
      $pattern[1] = '/Private:/';
      $replacement[0] = ''; // Enter some text to put in place of Protected:
      $replacement[1] = ''; // Enter some text to put in place of Private:
    
      echo preg_replace($pattern, $replacement, $title);
    }
    ?>

    Which you’d then use in place of the regular title using…

    Standard function – additional:
    <?php the_title_trim(); ?>

    Alternatively, use a filter to apply the changes to all titles…

    As filter function:

    <?php
    function the_title_trim($title)
    {
      $pattern[0] = '/Protected:/';
      $pattern[1] = '/Private:/';
      $replacement[0] = ''; // Enter some text to put in place of Protected:
      $replacement[1] = ''; // Enter some text to put in place of Private:
    
      return preg_replace($pattern, $replacement, $title);
    }
    add_filter('the_title', 'the_title_trim');
    ?>

    In this case you don’t have to add the call to the function… (and note the code is different for this usage). Copy and paste whichever you prefer into your theme functions.php

    Both were tested before posting..

    Let me know how they work out for you.

    Thanks for this. Worked perfectly.

    I am a real neophyte when it comes to PHP code.

    Exactly where do I paste the code within the Functions.php file? I cut and pasted the second recommended code and it worked…but I started getting error messages that eventually kept me from even logging into WP. I tried cutting and pasting the first code into the functions.php file and immediately got errors. Am I supposed to be replacing some other code with the code you provided?

    Thanks for any assistance you can offer!

    Assuming..

    ?>

    Is the last line in the file, replace that with..

    function the_title_trim($title)
    {
      $pattern[0] = '/Protected:/';
      $pattern[1] = '/Private:/';
      $replacement[0] = ''; // Enter some text to put in place of Protected:
      $replacement[1] = ''; // Enter some text to put in place of Private:
    
      return preg_replace($pattern, $replacement, $title);
    }
    add_filter('the_title', 'the_title_trim');
    ?>

    Or after should also be fine.. (like so)..

    ?>
    <?php
    function the_title_trim($title)
    {
      $pattern[0] = '/Protected:/';
      $pattern[1] = '/Private:/';
      $replacement[0] = ''; // Enter some text to put in place of Protected:
      $replacement[1] = ''; // Enter some text to put in place of Private:
    
      return preg_replace($pattern, $replacement, $title);
    }
    add_filter('the_title', 'the_title_trim');
    ?>

    If you receive errors, please copy and paste the error here so i can see specifically what the problem is.

    I have messed up badly, trying to follow this advice. Can you help dig me out?

    I have started to build
    http://www.how-to-hypnotize-anyone.com
    and have made two pages private. They are:
    domain/confirm
    domain/collect

    I tried to get rid of the
    Private:
    that appears in the headline of the two private pages by simply changing the word ‘Private:’ to ‘123’ in the post-format.php file in wp-includes. (Just a test.)

    That is, I changed
    $title = sprintf(__('Private: %s'), $title);
    to
    $title = sprintf(__('123: %s'), $title);

    When I went to the two private pages I got a 404 error message both times. I reverted to the orig line of code. Still 404. I changed the permissions on the file post-template.php to 644 and then to 777 (temporarily) and still got 404.

    Then I uploaded another copy to the post-format.php file from WordPress.org. Still getting the 404.

    Can you show me how to change the word ‘Private’ without incurring the 404?

    Or do I have to uninstall my WP site and start again? (That would not be too hard. There is not much content on the site yet.)

    Thanks,
    Len

    Don’t fiddle with core files..

    The code posted by myself works. I’ve explained how to use it, just read the post(s).

    Upload fresh copies of any WordPress core files (files not in the Themes or Plugins folders) that you have modified.

    Worked like a charm – thanks t31os! I used your *filter* function version of code. I was careful to place just your function code (without <?php ?> tags) inside my existing <?php ?> tags in my functions.php file. Otherwise it messed up my Multi-level Navigation plugin. Thanks again. Works beautifully!

    Thanks t31os!

    Here’s a slightly nicer looking version..

    function the_title_trim($title) {
    	// Might aswell make use of this function to escape attributes
    	$title = attribute_escape($title);
    	// What to find in the title
    	$findthese = array(
    		'#Protected:#', // # is just the delimeter
    		'#Private:#'
    	);
    	// What to replace it with
    	$replacewith = array(
    		'a', // What to replace protected with
    		'b' // What to replace private with
    	);
    	// Items replace by array key
    	$title = preg_replace($findthese, $replacewith, $title);
    	return $title;
    }
    add_filter('the_title', 'the_title_trim');

    Hi there t31os_, your code rocks! 🙂

Viewing 15 replies - 1 through 15 (of 23 total)
  • The topic ‘How to remove “Private” from private pages?’ is closed to new replies.