Okay
  Public Ticket #2702767
Post Title Custom Line Break
Closed

Comments

  •  1
    Ryan started the conversation

    I am trying to add a line break in [any] post title using this custom php function, which has been widely suggested for several years:

    <?php echo str_replace(' | ', '<br />', get_the_title()); ?>

    I prefer this instead of adding <br /> into each post title, as that display inconsistently. I was using this custom php function on my site with a previous version of the theme. Of course, I realize any theme update erases my changes to actual theme files.

    I want to add it back, but can't figure out which php file to amend, or if the tag to call the post title has changed.

    Are you able to point me in the right direction?

    Thanks!

  •  2,962
    Andrew replied

    Hi Ryan,

    Thanks for getting in touch.

    Please try to place the function in the single.php  script.

    Let me know how it goes.

    Thanks,

  •  1
    Ryan replied

    Hi Andrew,

    Thanks for the quick reply... That was the first place I tried placing the code, actually. I've also tried adding it in the main page.php and header.php scripts, as well as the page.php and page-header.php scripts in the "nectar -> helpers" subset.

    I also attempted a third-party plugin that lets you add custom php script (which I'm not really a fan of, but figured it was worth a shot)...and still nothing.

    What next? 

  •  2,962
    Andrew replied

    Hi Ryan,

    Allow me to escalate this to the developer to add in response.

    Thanks.

  •  1,073
    ThemeNectar replied

    Hey Ryan, sorry for the delay on this!

    You can actually handle this all from your child theme functions.php with a filter:

    add_filter('the_title','salient_child_map_br_in_title');
    function salient_child_map_br_in_title($title) {
        if( is_single() ) {
            return str_replace(' | ', '<br>', $title);
        }
        return $title;
    }
    
  •  1
    Ryan replied

    Thank you!

  •  1
    Ryan replied

    Hey, sorry to reopen this issue but after updating to version 13 this filter no longer works when adding to the child theme's functions file. Instead, it creates a gap of white space between the header/menu and the top of the page.

  •  1,073
    ThemeNectar replied

    Hey Ryan,

    I just tested with the snippet locally and can't replicate the issue. Can you activate the snippet again in your setup and provide a temporary admin login?