• After trying to add some text to the front of a post title if it has a certain author, the site is now pasting that text pretty much everywhere it can.

    I am trying to set this up by using this in my CPT functions file:

    function show_as_tip_in_feed($title, $id) {
    	$author_id = get_post_field('post_author', get_the_ID());
    	if(get_the_author() === "Labyrith")
    	{
    		$title = '<span style="color: #2D90CC;">[Official] </span>'.$title;
    	}
    	else
    	{
    		$title = $title;
    	}
    	return $title;
    }
    
    add_filter('the_title', 'show_as_tip_in_feed', 10, 2);

    The issues are that it not only pastes that text in every menu item, but it is also on every page, and I need a way to :
    a) Prevent it from placing itself in the menu items (or anywhere but the post title for that matter).
    b) Make sure it only works on my custom post type pages.

    Does anyone know how to do either of these?

Viewing 1 replies (of 1 total)
  • Heya

    This should do it

    function show_as_tip_in_feed($title, $id) {
    	$author_id = get_post_field('post_author', get_the_ID());
    	if((get_the_author() === "Labyrith") && ( in_the_loop() ))
    	{
    		$title = '<span style="color: #2D90CC;">[Official] </span>'.$title;
    	}
    	else
    	{
    		$title = $title;
    	}
    	return $title;
    }
    
    add_filter('the_title', 'show_as_tip_in_feed', 10, 2);

    as for b) I need a bit more info on what you need to accomplish.

    All the best!

Viewing 1 replies (of 1 total)
  • The topic ‘Title Prepend causing Repeats’ is closed to new replies.