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

Alex Scott Net Worth: How Rich is Alex Scott Actually?

Alex Scott Net Worth: How Rich is Alex Scott Actually?

Alex Scott is a former English footballer who is best known for her three stints at Arsenal as a right back. Moreover, she is the second most capped player in the history of the Women’s English national team with a total of 140 appearances for them. As of 2019, Alex Scott net worth is estimated […]

Reanne Evans Net Worth: How Rich is the English Snooker Player?

Reanne Evans Net Worth: How Rich is the English Snooker Player?

Reanne Evans is an English snooker player and the current World Women’s Snooker Champion. She has held the title a record 12 times, with 10 consecutive titles coming between 2005 and 2014. Evans is currently ranked number one on the World Women’s snooker Tour. As of 2019, Reanne Evans net worth is estimated to be £500,000. Evans was […]

Sasha Velour Net Worth: How Rich is the Drag Queen Actually?

Sasha Velour Net Worth: How Rich is the Drag Queen Actually?

Alexander Hedges Steinberg also known by the stage name Sasha Velour is an American drag queen and artist. Velour is best known for winning the 9th season of RuPaul’s Drag Race. As of 2019, Sasha Velour net worth is estimated to be $2.5 million. Velour was born on June 25, 1987, in Berkeley, California as the only child of Mark […]