WordPress.org

Ready to get started?Download WordPress

Forums

Remove the word *Private* on Private Pages (20 posts)

  1. omikami
    Member
    Posted 7 years ago #

    Is there any way to stop a page title from having the pre-fix "Private:" when making a page private? I'd like to make some pages private because they don't need to be part of the menu or clutter up the blog. It's great I can link to them. I thought to hardcode the side-menu but is that the only solution?

  2. variaas
    Member
    Posted 7 years ago #

    Saw a lot of posts asking the same thing with no reply. I figured it out, so here's my solution. In my functions.php file for the template I made a small tweak to how the_title function works. Copy and paste the two functions into your functions.php file and replace all instances of the_title() with asv_the_title(). All other functionality of the_title() should still remain the same.

    function asv_the_title($before = '', $after = '', $echo = true) {
    	$title = asv_get_the_title();
    	if ( strlen($title) > 0 ) {
    		$title = apply_filters('the_title', $before . $title . $after, $before, $after);
    		if ( $echo )
    			echo $title;
    		else
    			return $title;
    	}
    }
    
    function asv_get_the_title($id = 0) {
    	$post = &get_post($id);
    
    	$title = $post->post_title;
    
    	return $title;
    }
  3. Tfleming
    Member
    Posted 7 years ago #

    A question of clarification -

    do we replace the_title() throughout the site or just on the functions.php page?

    Even if the entire site - should be simple find&replace command, or are there any places where we shouldn't be replacing it?

  4. Tfleming
    Member
    Posted 7 years ago #

    I went with my assumptions above. I saved all the file in advance, which was good, as what I did didn't work. Not sure why... and unmade the edits before I forgot what all I was doing.

    Maybe I didn't do it right...

  5. drchrisheard
    Member
    Posted 7 years ago #

    What if the theme does not have a functions.php page at all?

  6. moshu
    Member
    Posted 7 years ago #

    Jsut create an empty plain (text) file and save it as functions.php. Copy the code into it. Upload.

  7. drchrisheard
    Member
    Posted 7 years ago #

    moshu, that did not work for me, for some reason. I don't know why.

    However, I achieved the same effect by modifying a function in wp-includes/post.php as follows:

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

    The only thing I changed was adding comment slashes to the "else if" lines. However this affects private posts as well as private pages, and would have to be repeated upon upgrading, so it's not a very good solution.

  8. moshu
    Member
    Posted 7 years ago #

    Well, the method above has 2 [two] steps:
    a. create the functions.php file
    b. replace ALL the instances of the_title with whatever is given above in the post

  9. blacloch
    Member
    Posted 7 years ago #

    Ok, just applied variaas's code to my functions.php. In my case the only the_title I changed was the one in Page Template file. Works a treat. Thanks variaas.

  10. Tfleming
    Member
    Posted 7 years ago #

    I used drchrisheard's solution, which worked better for me.

  11. jazeffect
    Member
    Posted 7 years ago #

    Another option - which does not require any coding - is to set up a private main page and then set up non-private sub pages. The links you include are to these sub pages and they do not get displayed with the PRIVATE: heading.

  12. variaas
    Member
    Posted 7 years ago #

    Glad that worked for your blacloch.

    @Tfleming and drchrisheard - if at all possible, I avoid editing core files. In the case of upgrading, you'll have to reapply the fix to the post.php file.

  13. leo6663
    Member
    Posted 6 years ago #

    I tried both and it didn't work for me.

    Does someone have a simple way to remove

    *private* from private posts.

    any help would be appreciated

  14. leo6663
    Member
    Posted 6 years ago #

    found this elsewhere:

    To get rid of the “Private: ” you can change the WordPress files yourself. I think I tried this once on an experimental blog that I have since binned.

    I think the only file to change is in wp-includes and is post-template.php

    “Private: ” (and a parallel for Protected posts) is part of the get_the_title function. It’s just some printed out text (sprintf). Change it to whatever you want, including nothing (as a string).

  15. JHouse
    Member
    Posted 6 years ago #

    Yessssss, leo6663, that helped me perfectly.

    Thanks for everybodys input.

    Ciao.

  16. azsportshub
    Member
    Posted 6 years ago #

    The weird part is, I inputted the code from above into my functions.php file and in development it worked great. Once I moved to production the "Private" still appeared. Any ideas why that would happen. Same files, same version of wordpress. Different database.

  17. stephenhodde
    Member
    Posted 6 years ago #

    function get_the_title has been moved to /wp-includes/post-template.php in version 2.3.1.

  18. azsportshub
    Member
    Posted 6 years ago #

    Is there any reason why this code in my functions.php file would not work with wordpress 2.3 or 2.13. I have tested it on both. Do I have to call functions.php anywhere?

  19. Clicknathan
    Member
    Posted 6 years ago #

    I've just tried variaas's solution in 2.3.1 and it does work.

    Make sure you're replacing the_title() with asv_the_title() and not get_asv_the_title().

    You don't need to replace it EVERYWHERE the_title() is, but you will need to replace it everywhere you don't want the word Private to show up.

    And no, azsportshub, you don't need to call functions.php, WP handles that for you.

  20. jenz
    Member
    Posted 6 years ago #

    You can just add this function to the functions.php file in your theme directory and it will remove the text "Private:" from all Private posts, pages:

    function remove_private_prefix($title) {
    $title = str_replace(
    'Private:',
    '',
    $title);
    return $title;
    }
    add_filter('the_title','remove_private_prefix');

    This way - you do not need to edit any core files or make changes to your template files.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags