I need to add a span class in the post title, something like this:
How to do that? Is this possible?
I need to add a span class in the post title, something like this:
How to do that? Is this possible?
Wouldn't the simplest approach be to use a filter on the_title()?
function add_span($title, $id) {
return $title .' <span class="title_span">' .get_post_meta($post_id, $key, $single) ."</span>";
}
add_filter('the_title', 'add_span', 10, 2);
This approach of course assumes you're storing your span data as a meta value.
First of all, the HTML on the image is not valid - close your <span>
with </span>
.
And yes, it's possible. I would do it with a custom field where you would enter what you want in your <span></span>
and then just display it in the theme file wherever you want it.
There are several ways to do this thing.
You can use custom meta key instead of your title area.
Simple usage : (Replace <?php the_title(); ?>
in your theme with this lines)
<?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 } ?>
Type your html codes in your HTML_title meta box than get your magic (:
Happy wordpress.