Site logo

Archived topic

How to get a line break in the content title of pages or posts ?

3 replies · Started by Frans on May 3, 2019

Viewing posts 1–4 of 4

If a content title is too long, Wordpress goes to a second line in the content title. How can this be forced ? I read an idea to use the "|" in the title e.g.

This is a title with a | custom break

and than add

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

somewhere. I tried to use Elements > Hooks > after_entry_title or before_entry_title, but nothing is replaced.

Is there a solution that works ?

Frans
(tests on local WAMP system)

Hi there,

Typically this isn't a good idea, as it can look really funky on mobile/certain screen sizes.

If you really wanted, you might be able to do this:

add_filter( 'the_title', function( $title ) {
    return str_replace( ' | ', '<br />', $title );
} );

Adding PHP: https://docs.generatepress.com/article/adding-php/

Not sure if it'll work, but it should.

Thanks ! I tried another approach: Subtitle issue

It works with some modifications:
- I installed the WP Subtitle plugin
- Made a hook with elements:

<?php echo '<h2>', the_subtitle(), '</h2>'; ?>

after-entry-title does not work; after_entry_header does work.

Frans

Glad you got it working :)

This archived topic is closed to new replies.