Advertisements
Connect with us

Tips & Tricks

Remove spaces when echoing the_title

Ever wanted to print or echo the WordPress title attribute without spaces?

Advertisements

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.

Advertisements

Random Search Terms

Title

Top Articles

powered by WassUp

Recent Posts: Fully Net Worth . com

LaTisha Scott Net Worth: How Rich is Marsau Scott’s Wife Actually?

LaTisha Scott Net Worth: How Rich is Marsau Scott’s Wife Actually?

LaTisha Scott is a Commercial Real Estate Developer who is the CEO of Infinity Properties. She is best known for starring in the reality television series called Love & Marriage: Huntsville. As of 2019, LaTisha Scott net worth is estimated to be $8 million. She was born on October 1, 1981, in the United States. […]

Myles Stephenson Net Worth: How Rich is the Singer Actually?

Myles Stephenson Net Worth: How Rich is the Singer Actually?

Myles Stephenson is a singer who is best known for winning the popular competition called The X Factor with the boyband Rak-Su back in 2017 in its 14th edition. He is now part of the awaited reality show called I’m a Celebrity…Get Me Out of Here!. As of 2019, Myles Stephenson net worth is estimated […]

Nadine Coyle Net Worth: How Rich is the Singer Actually?

Nadine Coyle Net Worth: How Rich is the Singer Actually?

Nadine Coyle is an Irish singer, actress, and model. She is part of the girl group called Girls Aloud which has been named the United Kingdom’s biggest-selling girl group of the 21st century. As of 2019, Nadine Coyle net worth is estimated to be $13 million. Coyle was born on 15 June 1985, in  Derry, […]