Posts Tagged “private-posts”

Private Posts: using a lock icon

I have some private posts here and there on my various WordPress blogs. WordPress is coded to display the word ‘Private:’ in front of whatever your title is, like this:


I had the thought that it might be better to replace the word with a lock icon, so that it would look like this:


In order to do this, I looked into the WordPress Codex and found the function that inserts the word ‘Private’.

  1. WordPress’ get_the_title(); function inserts the string `Private`
  2. this function is coded between lines 104-120 of the post-template.php file, located in the wp-includes directory.
  3. line 115 reads like this $private_title_format = apply_filters('private_title_format', __('Private: %s'));

Now that I knew what to change, I Googled for a lock image and found a no-copyright black one on Wikipedia, at size 360 x 360 pixels. I resized it to 16 x 16, and uploaded to the wp-includes folder. (I didn’t see why it should be in another).

Next, I coded it with an absolute url, since WordPress’s various functions to make clean urls meant that simply using <img src="lock.png"> didn’t work. Line 115 in post-template.php now looked like this example:

$private_title_format = apply_filters('private_title_format', __('<img src="//example.com/wordpress/wp-includes/lock.png"> %s'));