Connect with us

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; ?>&amp;<?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.

4 Comments

4 Comments

You must be logged in to post a comment Login

Random Search Terms

Title

Top Articles

powered by WassUp

Recent Posts: Fully Net Worth . com

Kieran Hayler Net Worth: How Rich is Katie Price’s Husband?

Kieran Hayler Net Worth: How Rich is Katie Price’s Husband?

Kieran Hayler is an actor who has appeared in Argumental, Loose Women and All-Star Family Fortunes. He was also a stripper and was associated as an entertainer with Adonis Cabaret Hen party Nights in London. As of 2019, Kieran Hayler net worth is estimated to be around £200,000. Hayler was born on March 22, 1987, […]

DJ Drama Net Worth: How Rich is the American DJ Actually?

DJ Drama Net Worth: How Rich is the American DJ Actually?

Tyree Cinque Simmons, who is better known as DJ Drama, is an American DJ and record executive producer who is the co-founder of Generation Now that includes top artists such as Lil Uzi Vert and Jack Harlow. As of 2019, DJ Drama net worth is estimated to be around $12 million. Simmons was born on […]

David Dobrik’s Net Worth

David Dobrik’s Net Worth

David Dobrik’s Net Worth: Know Everything About Him In recent years, we have seen the rise of many YouTubers. Ever since the time the market started booming with new YouTubers, this new way of entertaining people has come to the limelight. Speaking of popular YouTubers, we simply cannot miss out on David Dobrik. He is […]