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

Home Forums Support [Resolved] How to get a line break in the content title of pages or posts ?

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

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #888301
    Frans

    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)

    #888366
    Tom
    Lead Developer
    Lead Developer

    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.

    #888690
    Frans

    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

    #888954
    Tom
    Lead Developer
    Lead Developer

    Glad you got it working 🙂

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.