Reputation: 1583
Is there a way to remove the blank space between the words in the the_titel?
Example:
the_title() on one of my posts results in Merry Christmast
I want it to result in merrychristmast
Which means that I want to remove the blank space and use lowercase only.
Thanks
Edit: I was actually looking for a solution to the the_title-tag not the wp_title-tag. Sorry..
Upvotes: 1
Views: 9545
Reputation: 8541
wp_title();
I combined those two answers posted by Anthony and rzetterberg.
Use str_replace();
. It's faster for trivial replacements than RegEx. And if you add the necessary arguments to your wp_title();
we'll end up like this. Please note, that you'll have to add the strtolower();
function so that your title is displayed in lower case only.
<?php
echo strtolower(str_replace(' ', '', wp_title('', false)));
?>
the_title();
It's quite the same technique I posted earlier. You'll just have to change the arguments for the_title($before, $after, $echo);
.
<?php
echo strtolower(str_replace(' ', '', the_title('', '', false)));
?>
Note: Instead of using the_title('', '', false)
you could prepend it with a get_
. It does the same and fits your needs better.
<?php
echo strtolower(str_replace(' ', '', get_the_title()));
?>
Upvotes: 10
Reputation: 3996
get title -> remove white spaces (preg_replace) -> to lower case (strtolower)
<?php echo strtolower(preg_replace('/\s+/', '', wp_title("",false))); ?>
Upvotes: 2
Reputation: 10268
No, you would have to retrieve the value and remove the spaces yourself.
Like so:
$title = wp_title("", false);
Read more about the arguments for wp_title here
Upvotes: 0