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

Terry Fator net worth.

Terry Fator net worth.

Terry Fator net worth Terry Fator is a famous impressionist, comedian, singer, and ventriloquist from America. He has a net worth of $160 million, which he has accumulated over the years as a performer. He was born in 1965 in Dallas, Texas. He is capable of making more than 100 impressions of the ventriloquial kind […]

Michael Imperioli net worth.

Michael Imperioli net worth.

Michael Imperioli net worth James Michael Imperioli is an actor and TV writer with Italian-American origins. Michael has a net worth close to $25 million. Michael was born in March 1966 in the Mount Vernon area of New York. He grew up in the different areas of New York City, such as New Jersey, Ringwood, […]

Kurt Volker Net Worth: How Rich is the US Diplomat Actually?

Kurt Volker Net Worth: How Rich is the US Diplomat Actually?

Kurt Volker is an American diplomat. He served as the U.S. Ambassador to NATO and also as executive director of the McCain Institute of International Leadership. Kurt Volker net worth is as of 2019 is estimated to be $8 million. Volker was born on December 27, 1964, in Hatboro, Pennsylvania to Benjamin and Thelma Volker. […]