Trying to conditionally hide the "private" prefix in front of the page title on one specific page named 'members' only.

I used this code in functions.php to hide the prefix on all pages.

function title_format($content) {
return '%s';

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

Tried to hook into this with the if is_page ( 'members' ) in various ways, but so far the only result i managed to get is fatal errors.

  • Have you tried with the page ID instead? May you also show the code you uses when using the is_page() function? – Ethan Jinks O'Sullivan Sep 9 '16 at 19:25

This worked for me. One of the keys is that you have to make sure to pass the content through unchanged if it doesn't meet the condition.

function title_format($content) {
    if (is_page('members')) :
        return '%s';
    else :
        return $content;

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

This will only apply to the page with a slug of 'members', though, and it sounds like you're wanting to display a list of page titles on the Members page, and remove the prefix there. Is that the only place? Once the Member clicks the link, do you still want to omit the Private: and Protected: prefix on the title for the specific page?

If so, one approach would be to move all of the Protected: pages as children of the parent page. Use the code above, but modify the condition to determine if the pages are children of the members page.

Another approach would be to filter the title on the page template when you loop it out to the page. A function that I repurposed from csstricks:

function the_title_trim($title) {

    $title = attribute_escape($title);

    $findthese = array(

    $replacewith = array(
        '', // What to replace "Protected:" with
        '' // What to replace "Private:" with

    $title = preg_replace($findthese, $replacewith, $title);
    return $title;

And in your page template you would display the title like this:

echo the_title_trim(get_the_title());

That would only apply to that particular page template on the Members page assuming that you're creating a custom template for that page.

I hope this gives you a few ideas for how to approach it.

  • Thank you! I was actually thinking of going after the page template instead, since i do use a specific template for the member page, but after reading up in the codex i decide to first try with if is_page, but i couldn't figure out that i also had to use an 'else' statement – nicklas bryntesson Sep 9 '16 at 21:25

A simple solution without filters is by printing the title with:

<?php echo $post->post_title; ?>

This will print the original title without any prefix.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.