WordPress.org

Ready to get started?Download WordPress

Forums

the_title filter only for post/page title (3 posts)

  1. ETMSOFT
    Member
    Posted 2 years ago #

    Hi There, Im using this filter/hook in my functions.php file:

    function format_title($title) {
    	$last_space_position = strrpos($title, ' ');
    	if (in_the_loop() && $last_space_pos > 0) {
    		$title1 = substr($title, 0, $last_space_pos);
    		$title2 = substr($title, $last_space_pos);
    		$title = "$title1<br />$title2";
    	}
    	return $title;
    }
    add_filter('the_title', 'format_title');

    What Im doing is to break the title into 2 lines, but I dont want this on titles within single.php, where I have the pagination functions previous_post_link and next_post_link

    How do I solve this ? Is there any conditional tag I can add to this 'if' ?

  2. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    if( !is_single() ) add_filter('the_title', 'format_title');

  3. ETMSOFT
    Member
    Posted 2 years ago #

    Thanks esmi, but not working, what I want is to apply the filter except for titles generated within previous_post_link and next_post_link functions

Topic Closed

This topic has been closed to new replies.

About this Topic