I have a WordPress website where I manage various products through a custom post type named ‘product’. I want to display the registered trademark symbol as superscript using tags. However, when I add <sup>®</sup> to the title, it doesn’t render correctly and instead shows the HTML code itself.
I’ve attempted to use several HTML tags, but they all display as text rather than functioning correctly in the title, like <strong>, <em>, <b>, <i>, and also a CSS class with <span class="superscript"></span> that I created.
This code works well on individual product pages, but on archive pages, the HTML tags still appear as text. I’m using a self-hosted WordPress site with the Astra theme and the Custom Post Type UI plugin.
Is there a method to ensure that WordPress renders HTML properly in titles on all types of pages, including archives?
WordPress uses different sanitization rules for different page types. Archive pages have stricter filtering that auto-escapes HTML entities. Don’t fight it - use CSS pseudo-elements instead. They’re way more reliable. Add this to your stylesheet: .trademark:after { content: '®'; vertical-align: super; font-size: 0.8em; } Then update your function to wrap trademark symbols with <span class="trademark"></span>. You’re just adding a CSS class, so it skips title sanitization completely. Looks exactly like superscript tags but works everywhere - archives, feeds, meta tags, wherever HTML would normally break.
WordPress sanitizes titles differently on archive pages - they strip HTML by default for security. You’ll need to hook into pre_get_posts or use a filter like single_post_title instead. I ran into this same thing with chemical formulas in titles. What worked for me was creating a custom function that runs earlier and uses wp_kses() with specific allowed tags. Add this to your functions.php: php function allow_html_in_titles($allowed, $context) { if ($context === 'post') { $allowed['sup'] = array(); } return $allowed; } add_filter('wp_kses_allowed_html', 'allow_html_in_titles', 10, 2); This tells WordPress that <sup> tags are safe. Then update your existing function to work on archive pages by removing the is_singular() condition.
try using wp_kses_allowed_html() to let the tag work in titles. by default, wp removes html for security, so make sure to allow it! also, check if you need to use the wp_title filter to fix text showing up raw.