Changing the Private and Password Protected labels

If you've used the private or password-protected status for posts or pages, you've probably noticed that WordPress adds labels to the titles, and there is no setting allowing you to change it. In Listing 9-26, you'll do a search and replace on the private page's title to replace the default "Private: " label with your own "Members Only" label.

Listing 9-26. Removing the "Private" prefix from private pages function custom_private_title($title) {

return str_replace(_("Private: "), 'Members Only: ', $title);

add_filter('private_title_format', 'custom_private_title');

In this case, I've left in the internationalization function (the two underscores) which I'll explain in more detail later in this chapter. When you're filtering built-in WordPress strings like this, it's important to use translatable strings. In this case, you're searching for the word Private followed by a colon, but if this were a plugin that you intended to distribute on WordPress Extend, you'd quickly find that your replacement wouldn't appear to users who've set up WordPress in another language.

0 0

Post a comment