How to add a line break in a WordPress post title (medium.com)
over 8 years ago from Geoff Canady, Front End Dev at The Zebra
over 8 years ago from Geoff Canady, Front End Dev at The Zebra
This will break RSS titles, page title and lots of other things. There is a reason why best practices tell you to separate content from presentation.
Yeah this is a bad solution to the problem.
Anywhere you want to display a page/post title, you need to implement str_replace. And since it's tied to the theme, if your client ever changes theme you'll have pipes everywhere!
Came here to say exactly this. I've used custom fields in the past as my solution. Much more heavy-handed though as it requires some CSS/theme customization too. I set mine up so that if the custom field for my title was used, it replaced the built-in WP title on blog and permalink pages.
RSS still saw the built-in WP titles, and I still got my customized formatting for titles on the site itself. Win-win!
Short post, cool solve. Have an upvote!
I don't believe this is a very good solution. The main WP title should stay clean for use in the Admin, RSS,
tag, etc. I would rather implement an additional title field in the admin and allow tags or some other HTML element to signify breaks, then that "Editorial Title" can be output on the page.For several of my editorial sites we already implement similar alternate title fields for things such as a short story title or a combined hed/dek title.
It would be worth exploring options other than an actual tag to indicate breaks since at different breakpoints that title should probably break at different points
Can't think of another solution, but this could really break the content later on. At least try applying it using a separate plugin, so whenever your client changes the theme, he won't lose these line breaks.
This would be better accomplished by using a hook. Doing this will affect all functions who outputs the title.
I suggest an IF statement, to just remove those extra characters and leave the title in just one line on special cases like RSS, meta tags, etc...
How about using real enter character and using?
h1{ white-space: pre; }
Won't it work?
What is a real enter character? Not sure I know how to create one, which means I assume my user wouldn't either.
I mean type something, hit enter key and continue typing. I have a little knowledge about WordPress. Doesn't it let you enter \n
characters?
Designer News
Where the design community meets.
Designer News is a large, global community of people working or interested in design and technology.
Have feedback?
Login to Comment
You'll need to log in before you can leave a comment.
LoginRegister Today
New accounts can leave comments immediately, and gain full permissions after one week.
Register now