• Resolved DavidSortOf

    (@davidsortof)


    I found that I can add a little html to a page title in Quick Edit, and it will work, in the sense that tags are implemented rather than displayed as code.

    The only problem is that this “code view” is now displayed in the page list.

    I’ve tried using Code View in Gutenberg, and using a Classic Editor plug-in to add html to page titles, but doing that with both these methods changes the title to display the code. If I were to name a page “This is a <em>Page</em> Title,” that would be exactly as it would display. So Quick Edit wins.

    But might there be a way to edit a page title with html, as I can with Quick Edit, but without it then displaying this “code view” in the page list? Is there perhaps a plug-in that would enable that?

    Thanks!

    • This topic was modified 1 year, 9 months ago by DavidSortOf. Reason: Made a few goofy little mistakes
Viewing 2 replies - 1 through 2 (of 2 total)
  • The following little snippet solves what you mean:

    function custom_esc_html( $safe_text, $text ) {
     if( is_admin() ) {
      return $text;
     }
     return $safe_text;
    }
    add_filter( 'esc_html', 'custom_esc_html', 10, 2);

    However, this should be used with caution. The background: this hook uses the filter of esc_html(). esc_html() is used to secure texts before outputting them to the browser. This converts e.g. < to %lt; so the browser doesn’t interpret them as HTML code anymore but e.g. outputs

    <em>italic</em>

    instead of italic. By leveraging this (even if it’s only in the admin area), a potential attacker can influence your browser.

    Example:
    If after inserting the above code into a page title in your project, you put

    <script>alert("aaaa");</script>

    then you will always see an alert window when calling pages in the backend where this is output.

    For this reason I would advise you not to do this, even if it is theoretically possible as you can see. I therefore do not describe here how to insert the code.

    Thread Starter DavidSortOf

    (@davidsortof)

    Ok thanks for that, especially with the warning and background. I figured it would involve something like this. I’m going to leave things alone regarding this. ; )

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Edit HTML of a Page Title?’ is closed to new replies.