Forums

Filtering Titles? (3 posts)

  1. Tom Belknap
    Member
    Posted 3 years ago #

    Forgiveness to all if I've not looked deeply enough, but this is rather strange. I'm looking here and not seeing what I'm supposed to. I could be out of my mind, though. . .

    I have a plugin which will filter the title of a post, but what I'm finding is that I've had to put in two filters, the_title for the title as it appears within the page and single_post_title for the title as it appears within the HTML <title> tags.

    Is there another, more convenient way to do it? I need this to happen on display as a filter, not on database save, as the page will change based on user input (its a user profile page plugin).

    Thanks in advance!!

  2. Tom Belknap
    Member
    Posted 3 years ago #

    w00t! Worse than I thought: the filters I'm using are converting all page and post titles on the page, when they're only supposed to change the current one. Anybody have any ideas?

  3. kerkness
    Member
    Posted 3 years ago #

    You can check if the title you're filtering belongs to the current post by comparing it to the global $post->post_title variable.

    Here is an example filter

    function my_title_filter($title)
    {
    	global $post;
    	if( $title == $post->post_title ){
    		$title = 'My New Filtered Title';
    	}
    	return $title;
    }

Topic Closed

This topic has been closed to new replies.

About this Topic