• Resolved jrcollins

    (@jrcollins)


    I want to change the title based on the category. For example, if the current post is in category x or y, use title a, else use title b.

    Here’s the code I tried using:

    add_filter( 'related_posts_by_taxonomy_shortcode_defaults', 'related_shortcode_title', 10, 2 );
    
    function related_shortcode_title( $defaults, $post ) {
        
    	if ( has_category('44,45') ) {
    	$defaults['title'] = 'Related Products';
    	}
    	else {
    	$defaults['title'] = 'Related Posts';
    	}
        
    	return $defaults;
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter jrcollins

    (@jrcollins)

    Ok, I realize what I did wrong. It should be:

    add_filter( 'related_posts_by_taxonomy_shortcode_defaults', 'related_shortcode_title', 10, 2 );
    
    function related_shortcode_title( $defaults, $post ) {
        
    	if ( has_category(array(44,45))) {
    	$defaults['title'] = 'Related Products';
    	}
    	else {
    	$defaults['title'] = 'Related Posts';
    	}
        
    	return $defaults;
    }
    Plugin Author keesiemeijer

    (@keesiemeijer)

    Hi jrcollins

    Did you solve the issue or is it still not working?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to filter title?’ is closed to new replies.