Put HTML tags into wordpress post title
May 25, 2010 · Print This Article
You don’t want to go putting HTML tags directly into post titles. It might show up OK on your own site, but it can be problematic. For example, your titles through RSS will show the tags as next, not render them, here is almost-as-simple way to go about it.
1. Enter title without HTML
2. Create a custom field “HTML_title” for the title with HTML
3. Output custom field on pages you want the HTML
For example, on the single.php page where you would have used
<h1><php the_title(); ?></h1>
Now you use
<?php
$html_title = get_post_meta($post->ID, "HTML_title", true);
if ($html_title) { ?>
<h1><?php echo $html_title; ?></h1>
<?php } else { ?>
<h1><?php the_title(); ?></h1>
<?php } ?>
This checks and sees if that custom field is set. If it is, it outputs that. If not, it uses the regular function.
Because the RSS templates use the regular the_title() function, your titles are same from being weirdified in feed readers.





















[...] WordPress Coding: Programmatically Add Post Tags How-To: Adding categories and tags to your posts Put HTML tags into wordpress post title Adding Categories And Post Tags Boxes For Custom Post Type In WordPress How to Add WordPress Tag [...]