HTML spans within titles
-
I am wanting to put spans around certain words in my post titles.
So the html code might look something like this:
<h2>THIS IS THE <span class=”styled-span”>EFFECT</span> I AM AFTER!</h2>I am not sure how to do this as obviously posts are dynamically generated.
I tried to enter the span into the Title field when I write a new post, and it kind of worked, but entered the title twice.
Can anyone help?
-
WP 2.0.3 can do this. For WP 1.5 you can use this plugin: http://www.thunderguy.com/semicolon/wordpress/safe-title-wordpress-plugin/
All solved, thank you :O)
I lied, not all solved .. if you look on my homepage: http://www.simonbailey.co.uk .. the first post reads:
KOKOPELLI”>STAR KOKOPELLI
when it should read:
STAR KOKOPELLIThe html I entered into the title field is:
STAR <span class=”dark-grey-text”>KOKOPELLI</span>
It is outputting the code quite strangely.
Are there any solutions for this?
Open the
index.php
file in your theme and find this line:<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>
Now change it to this:
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php echo strip_tags( the_title('', '', false) ); ?>
It should work, since I use the same to take care of the spans I have in my post titles. You’ll also notice that the the comments link is also fishy when you use spans in the title. I fixed it by changing the core
comments_popup_link()
function (which isn’t a neat solution, since you might have to change it manually after a WordPress version upgrade).Look at your source – the span class is also in the title-tag (permanent link to …).
I think, this is your problem.That’s fantastic π
nastaliq that has worked perfectly, thank you so much.
How do I also edid the code to make this change for the ‘Posted in’ section, as at the moment the ‘No comments’ text is also showing some tags.
Not quite sure how to change that.
By the way – the code for this Posted section is:
<p class=”postmetadata”>Posted in <?php the_category(‘, ‘) ?> | <?php edit_post_link(‘Edit’, ”, ‘ | ‘); ?> <?php comments_popup_link(‘No Comments »’, ‘1 Comment »’, ‘% Comments »’); ?>
This is currently displaying:
Posted in GenERAL WAFFLE! | Edit | KOKOPELLI!”>No Comments Β»
The ‘KOKOPELLI!”>’ being the part where the tags need to be stripped from.
Hope you can help!
Okay, here’s what you can do for comments…
Open your favourite text editor and paste the following code in it:
<?php
function my_comments_popup_link($zero='No Comments', $one='1 Comment', $more='% Comments', $CSSclass='', $none='Comments Off') {
global $id, $wpcommentspopupfile, $wpcommentsjavascript, $post, $wpdb;
global $comment_count_cache;if (! is_single() && ! is_page()) {
if ( !isset($comment_count_cache[$id]) )
$comment_count_cache[$id] = $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = $id AND comment_approved = '1';");$number = $comment_count_cache[$id];
if (0 == $number && 'closed' == $post->comment_status && 'closed' == $post->ping_status) {
echo $none;
return;
} else {
if (!empty($post->post_password)) { // if there's a password
if ($_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password) { // and it doesn't match the cookie
echo(__('Enter your password to view comments'));
return;
}
}
echo '<a href="';
if ($wpcommentsjavascript) {
if ( empty($wpcommentspopupfile) )
$home = get_settings('home');
else
$home = get_settings('siteurl');
echo $home . '/' . $wpcommentspopupfile.'?comments_popup='.$id;
echo '" onclick="wpopen(this.href); return false"';
} else { // if comments_popup_script() is not in the template, display simple comment link
if ( 0 == $number )
echo get_permalink() . '#respond';
else
comments_link();
echo '"';
}
if (!empty($CSSclass)) {
echo ' class="'.$CSSclass.'"';
}
echo ' title="' . sprintf( __('Comment on %s'), strip_tags($post->post_title) ) .'">';
comments_number($zero, $one, $more, $number);
echo '</a>';
}
}
}
?>Make sure that there are no empty spaces before
<?php
and after?>
. Now save the file asmy-hacks.php
and upload it to your root wordpress directory.Next, in the administration panel, go to Options > Miscellaneous and check “Use legacy my-hacks.php file support”.
Now, search for
comments_popup_link
in your theme’s files. Replace every occurrence withmy_comments_popup_link
. You don’t have to change the function’s parameters.That should work.
(Also, about post titles, you also need to change the code for your post titles in
single.php
, just like you did forindex.php
.)Thanks alot nastaliq.
I have made the php file and uploaded this, also I have changed the settings within my administration panel.
I don’t really understand what you mean by comments_popup_link in my themes files.
I can see comments-popup.php is this what you mean?I have looked in this file and can see no instances of comments_popup_link
Is this what you mean?
I have changed the code in my single.php file and that works perfectly so thanks alot.
Comments are still not working though π
Oh, I meant to say that search within the theme files, that is to say that search in the code of those files.
Like in the code you posted in one of your previous posts, you can see
comments_popup_link
, right? Just replace that withmy_comments_popup_link
, and wherever else you are using this function.Fantastic, all fixed π
Thanks alot nas π
I created an account on here just to thank you, nastaliq, for that comments_popup_link code. I spent all night trying to fix that and was stumped until I found this threat. Thanks again.
- The topic ‘HTML spans within titles’ is closed to new replies.