admin管理员组文章数量:1279056
On my test case, the page' title is "Privacy". The straightforward approach
strtolower(the_title())
also returns "Privacy" -- still with a capital P. I also tried
mb_strtolower(the_title())
and
mb_strtolower(the_title(), 'utf8')
with similar results.
Not sure if it matters, but my wp-config.php has
define('WPLANG', '');
define('DB_CHARSET', 'utf8');
On my test case, the page' title is "Privacy". The straightforward approach
strtolower(the_title())
also returns "Privacy" -- still with a capital P. I also tried
mb_strtolower(the_title())
and
mb_strtolower(the_title(), 'utf8')
with similar results.
Not sure if it matters, but my wp-config.php has
define('WPLANG', '');
define('DB_CHARSET', 'utf8');
Share
Improve this question
edited Jan 17, 2012 at 1:00
Jon Pincus
asked Jan 16, 2012 at 22:57
Jon PincusJon Pincus
831 gold badge1 silver badge5 bronze badges
1
|
3 Answers
Reset to default 11lowercasing the title
If I'm understanding you correctly, you should be doing:
strtolower(get_the_title());
or
print strtolower(get_the_title());
if you want to display it. Below is an explanation as to why.
the_title() vs. get_the_title()
The function the_title()
prints the current post's title unless you pass false
as its third argument. Unless you call it like:
$title = the_title('', '', false);
The title will be printed, and the $title
variable won't contain anything. This matters because calling strtolower()
on an empty variable doesn't do very much.
You want to use get_the_title()
function in most cases where you're looking to fill a variable with the content posts title.
Note, however, that if you're not currently in a loop, you'll need to pass a post ID to get_the_title()
. In almost all cases when on a single post or page you can do this by using:
get_the_title($post->ID);
as the $post
variable should be in the global scope.
I think the best method for this is by using CSS (text-transform: lowercase).
But if you want to use PHP, WP for this you can use: <h1><?php echo strtolower( get_the_title() ); ?></h1>
Here is a great plugin for doing this. It's on my website, WordPress, Github and others. It's 100% free, with no membership versions. Please feel free to download it. This does it on the data level, which allows you to change it later, or do it on some and not others. It's a good option, and as I said. Works Great!
My Site:
https://properprogramming/tools/wp-change-titles-case/
Wordpress: https://wordpress/plugins/change-titles-case/
本文标签: How do I convert a page39s title to lower case
版权声明:本文标题:How do I convert a page's title to lower case? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741220102a2360806.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
thetitle()
is not a WordPress function. – fuxia ♦ Commented Jan 17, 2012 at 0:29