WordPress.org

Ready to get started?Download WordPress

Forums

How to remove "Private" from private pages? (24 posts)

  1. abhik03
    Member
    Posted 5 years ago #

    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

  2. baalam
    Member
    Posted 5 years ago #

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

  3. agitcorp
    Member
    Posted 5 years ago #

    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?

  4. t31os
    Member
    Posted 5 years ago #

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

  5. agitcorp
    Member
    Posted 5 years ago #

    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?

  6. t31os
    Member
    Posted 5 years ago #

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

  7. t31os
    Member
    Posted 5 years ago #

    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.

  8. rickibird
    Member
    Posted 4 years ago #

    Thanks for this. Worked perfectly.

  9. Coryan
    Member
    Posted 4 years ago #

    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!

  10. t31os
    Member
    Posted 4 years ago #

    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.

  11. lenmcgrane
    Member
    Posted 4 years ago #

    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

  12. t31os
    Member
    Posted 4 years ago #

    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.

  13. reidwalley
    Member
    Posted 4 years ago #

    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!

  14. tofirius
    Member
    Posted 4 years ago #

    Thanks t31os!

  15. Mark / t31os
    Moderator
    Posted 4 years ago #

    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');
  16. Marcelo Pedra
    Member
    Posted 4 years ago #

    Hi there t31os_, your code rocks! :)

  17. backpocket
    Member
    Posted 4 years ago #

    I found another really simple fix...

    At the bottom of functions.php just add the following code:

    <?php
    function bfa_remove_word_private($string) {
    $string = str_ireplace("private: ", "", $string);
    return $string;
    }
    add_filter('the_title', 'bfa_remove_word_private');
    ?>

    Worked for me anyway!

  18. eq2bum
    Member
    Posted 4 years ago #

    Thanks guys, this is just what i was looking for.

  19. eq2bum
    Member
    Posted 4 years ago #

    hmm...well, my functions.php doesn't have end with a ?> so i am a little confused.

    it starts with a <?php there are a couple functions for registering the left and right sidebar then no ending ?>

    any ideas?

  20. PSG
    Member
    Posted 4 years ago #

    Hi t31os_,

    Your code works very well in Firefox but shows 404 error on IE8 and Safari 4.0.3.

    help!

    Cheers
    PSG

  21. Mark / t31os
    Moderator
    Posted 4 years ago #

    @PSG:
    It's not browser specific, all it does is replace some data in a string, there should be absolutely no difference between browsers.

    @backpocket:
    preg_replace is a regular expression function. str_replace is proberly faster for this usage, but they essentially do pretty much the same. The aim of the previous code was to keep it simple, so those using it could examine and perhaps get some understanding of what's doing what (to some degree).

  22. PSG
    Member
    Posted 4 years ago #

    Sorry about the earlier posting. It does not show when your are logged out. Was checking other browsing in logged out mode.

    Anyway found the best way out: a Plug in called 'Exclude Pages'

    works super and easy no codes or core files to mess with.

    http://wordpress.org/extend/plugins/exclude-pages/

    Cheers
    P

  23. uandras
    Member
    Posted 4 years ago #

    okay, but what if i use wordpress blog in itself, not as just a motor?

  24. gsawiris
    Member
    Posted 4 years ago #

    hi some of my post titles look like this:

    <b>Da dana dan</b> songs – Paisa Song from <b>Da Dana Dan</b> – Vox

    when i add this code to the functions file nothing happens:

    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(
    '#<b>#',
    '#</b>#'
    );
    // What to replace it with
    $replacewith = array(
    'test',
    'test2'
    );
    // Items replace by array key
    $title = preg_replace($findthese, $replacewith, $title);
    return $title;
    }

    any ideas? thanks

    this is funny i went to edit this post and noticed that my <b> symbol had been replaced with "& lt;b& gt;"

    when i put put the same code in place of <b> in the function.php filter it works fine.
    i can finally get rid of unwanted characters appearing in my post titles.

    thanks

Topic Closed

This topic has been closed to new replies.

About this Topic