Quick Solution
To remove the “Private:” prefix from your WordPress post titles, add a custom function to your theme’s functions.php
file. This function uses str_replace
to strip the “Private: “ text, ensuring your titles appear clean and professional on your website.
function remove_private_prefix($title) {
$title = str_replace('Private: ', '', $title);
return $title;
}
add_filter('the_title', 'remove_private_prefix');
When working with private posts in WordPress, you might notice that the word “Private:” automatically appears before the title of your content. While this is useful for identifying private posts, it can be less desirable when displaying titles on your website. Fortunately, there’s a way to remove the “Private:” prefix from your WordPress titles without affecting the functionality of private posts.
In this article, I’ll guide you through a simple method to remove this prefix, helping your content appear cleaner and more professional.
Why Does WordPress Add “Private:” to Titles?
WordPress adds the “Private:” prefix to the titles of private posts to indicate that the content is not accessible to the public. This feature is helpful in the admin area, but when it comes to the front end of your website, it may not always be necessary or aesthetically pleasing.
Removing the “Private:” Prefix from Titles
There are a couple of ways to remove the “Private:” prefix from your titles, depending on your comfort level with coding. Below, I’ll outline a method using a custom function in your theme’s functions.php
file.
Using a Custom Function
One of the simplest ways to remove the “Private:” prefix is by adding a custom function to your theme’s functions.php
file. Here’s how you can do it:
- Access Your Theme’s
functions.php
File:- Go to your WordPress dashboard.
- Navigate to
Appearance > Theme File Editor
. - Open the
functions.php
file.
- Add the Following Code:
function remove_private_prefix($title) {
$title = str_replace('Private: ', '', $title);
return $title;
}
add_filter('the_title', 'remove_private_prefix');
- Save Your Changes:
- After adding the code, click the
Update File
button to save your changes.
- After adding the code, click the
This code snippet works by using the str_replace
function to remove the “Private: “ text from the beginning of your post titles.
Conclusion
With this simple tweak, you can now display private post titles on your website without the “Private:” prefix. This small change can make a big difference in the presentation of your content, especially if you regularly work with private posts.
Remember, this method only alters the title display and does not change the privacy settings of your posts. Your content will remain private, visible only to authorized users.
Feel free to reach out if you have any questions or need further customization!