Support » Fixing WordPress » Removing &nbsp and – on Posts & Pages Title

  • When you do View Source on website pages and posts, you will see &nbsp and &#8211 in the Title.
    See image:
    charactorsonpagetitles

    I need help with a code or hook to remove those and prevent from showing again.
    Thank you

    • This topic was modified 1 year, 8 months ago by Manny.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Dion

    (@diondesigns)

    Those are called HTML entities. You may encounter them when you view the source of an HTML document, but all browsers will render HTML entities to their corresponding character when displaying the actual HTML document. For example, the   entity is a non-breaking space, which allows two words to be considered as one when a browser determines where to start new lines in a block of text.

    Here’s another example:

    © will be rendered as ©

    So…there’s no need to worry about them. 🙂

    Thread Starter Manny

    (@mannyo)

    @diondesigns
    It sounds like you are saying that yhlmthere is nothing one can do to control those..

    That doesn’t sound right because I know a lot of websites without those in thier title even when they added line breakers.

    And I looked at them from the same browser.

    It seems that there are things you can do that can control.

    That’s what I’m looking for.

    Dion

    (@diondesigns)

    That’s a different question than I thought you were asking.

    For better or worse, WordPress converts a number of characters to HTML entities. It is done when you enter text in the editor (worse with the block editor than the classic editor). And unless disabled with a plugin or custom code, it is also done when text is displayed on the frontend. (Note that this “texturize” process oftentimes changes the actual character being displayed in addition to converting characters to entities.)

    Some of this is necessary because there is no way to guarantee a browser will load/use the screen font defined for the text. If a character is not available in the font, use of an HTML entity will allow the browser to select a replacement character (if available) as opposed to it using a different font, or worse, displaying a weird rectangle.

    If you want to minimize the use of HTML entities, use the classic editor and disable the wp_texturize hook/function in the WordPress core. I personally do both, though not to minimize the use of entities. Among other things, I don’t like WordPress deciding that what I entered is wrong, and changing characters to what it thinks I should use.

    Thread Starter Manny

    (@mannyo)

    @diondesigns
    What’s the actual hook to disable it for the Title on a Twenty Twenty and Twenty Twenty-Two theme?
    I tried this add_filter(‘run_wptexturize’, ‘__return_false’); and it is not working.

    Thanks

    • This reply was modified 1 year, 7 months ago by Manny.
    • This reply was modified 1 year, 7 months ago by Manny.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Removing &nbsp and – on Posts & Pages Title’ is closed to new replies.