Support » Fixing WordPress » the_title filter only for post/page title

  • 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’ ?

Viewing 2 replies - 1 through 2 (of 2 total)
  • esmi


    Forum Moderator

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

    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

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘the_title filter only for post/page title’ is closed to new replies.