Archived topic
Avoid post title breaking to one word in a new line
3 replies · Started by Ian on September 5, 2019
Is it possible to make sure the post title (h1) does not break to a new line just for one word. I would like it to at least break to two words or more.
Hi there,
it would probably require some Javascript to calculate there is an orphan word. But then what does it do with it - if it forces it to one line then that line would overflow the container, which wouldn't be pretty.
I did find this on StackOverflow which stops orphans by breaking the title into groups of words:
https://stackoverflow.com/a/32895944
The function call at the end of the code:
noMoreLonelyWords("p", 3);
Targets <p> tags and splits sentence into groups of 3 words. So switch the P to H1 and see how that works.
Thanks for that David, I’ll give that a go.
You're welcome