Tips & Tricks
Remove the title attribute using jQuery
In WordPress, when you use wp_page_menu
your anchor attribute’s usually carry a title with the same name. I’m not sure if it’s correct to do this, but it bother me when I hover over a page menu navigation link and I get a hover of the title.
So on my site I used jQuery to remove the title:
$("#nav a").removeAttr("title");
Pretty simple huh?
Tips & Tricks
Remove spaces when echoing the_title
Ever wanted to print or echo the WordPress title attribute without spaces?
This little trick can be useful for calling custom functions and printing the title with out spaces for W3C compatibility. I used this trick in a new theme called Galleria, which will be out for public download in the coming days.
Using this comes in handy for a delicious text link:
<?php $title = get_the_title(); ?> <a href="http://del.icio.us/post?url=<?php echo $title; ?>&<?php echo str_replace(" ", "%20", $title); ?>"> Bookmark This (<?php echo $title; ?>)</a>
What I am doing is calling $title = get_the_title();
and using str_replace(" ", "%20", $title);
to replace empty spaces with a %20
, which is used in URL encoding empty spaces.
Alternatively you can use a dash or underscore.
Thanks to Jason Boyle for his adaption.
Tips & Tricks
Display the_excerpt only if there is text
Have you ever wanted to display the excerpt only if you write one? A simple couple lines of code can display the_excerpt
any where you like.
In my new theme, I am using this coded trick to display the excerpt on a single post only if I’ve got text inside. Usually if you use the_excerpt
and you don’t have one, it will fake one for you.
This is not something that I wanted to do on the single post page. So I used the following code to check if the excerpt existed.
if ( !empty( $post->post_excerpt ) ) :
Once this action is taken into account, you can factor in what code you want to out put if the post_excerpt
isn’t empty.
if ( !empty( $post->post_excerpt ) ) : the_excerpt(); else : false; endif;
The above code checks if there is an excerpt and print’s it to the screen. If there isn’t an except, it doesn’t do anything.
Tips & Tricks
Add a shortcode
This is a simple one.
/** * Your Blog title * */ function my_blog_title() { $blogname = get_bloginfo('name'); return '<span class="blog-title">' . $blogname . '</span>'; } add_shortcode('blog-title', 'my_blog_title');
Just add this to your functions.php file and then add [blog-title] in any post or page and it will return your Blog Title. :)
-
Tips & Tricks7 months ago
WordPress Security Hacks
-
Pages2 months ago
Write For Us – Guest Post
-
Showcase2 months ago
StylizedWeb.com
-
News2 months ago
How to: Show/Hide any div box with jQuery in WordPress
-
Tips & Tricks6 months ago
How to: show/hide a widget in WordPress with jQuery
-
Plugins6 months ago
Top Membership plugins
-
Tips & Tricks2 months ago
Limit the characters that display on the_title
-
Tips & Tricks1 week ago
Remove spaces when echoing the_title
Bryan
March 11, 2009 at 9:32 pm
Hey, yeah, that’s really simple! Right now I’m doing…
$clean_pages = wp_list_pages(‘title_li=&&echo=0’);
$clean_pages = preg_replace(‘/title=\”(.*?)\”/’,”,$clean_pages);
echo $clean_pages;
Frosty
March 12, 2009 at 12:55 pm
Yes, a lot easier, but it won’t work on any browser that has javascript disabled.
andy
March 21, 2009 at 11:25 am
correct me if i am wrong please….do i just put this code in my head section:
$(“#div_id”).removeAttr(“title”);
and that should remove the title attribute from displaying when I hover over any item within the #div_id ?
Note: it is not an a tag I am trying to remove the title attribute from, but rather a div tag.
Austin
March 21, 2009 at 2:24 pm
Yes, the removeAttr should remove any title attribute if there is one, as long as javascript is enabled.
Unibands
October 29, 2009 at 5:08 am
Yes, but you of course need the jQuery library too. And you put this like so in your tags.
//
Unibands
October 29, 2009 at 5:12 am
Seems like code etc doesn’t show up in the comments.
Pingback: Remove WordPress Title Attribute | ClayCazier.com