Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove "Protected" text in title h1 of protected wordpress pages

Tags:

php

wordpress

Had a search around and can't seem to find any options to do this, found quite a few posts on how to personalise the login page but nothing about removing the Protected text that is automatically added before the page title, anyone able to shed some light?

EDIT:

Found the answer here in the end http://wordpress.org/support/topic/how-to-remove-private-from-private-pages, code as follows

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');
like image 582
Nick Avatar asked Oct 20 '25 07:10

Nick


2 Answers

There are dedicated wordpress filters ('private_title_format' and 'protected_title_format') applied to the post title when the post visibility is set to private or protected and you should use that in your functions.php instead of replacing all post-titles:

add_filter( 'private_title_format', 'myprefix_private_title_format' );
add_filter( 'protected_title_format', 'myprefix_private_title_format' );

function myprefix_private_title_format( $format ) {
    return '%s';
}
like image 186
benedikt Avatar answered Oct 21 '25 20:10

benedikt


Found the answer here in the end http://wordpress.org/support/topic/how-to-remove-private-from-private-pages, code as follows

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');
like image 40
Nick Avatar answered Oct 21 '25 22:10

Nick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!