获取,修改,然后在 wordpress 中打印帖子标题 [英] Get, modify, then print post title in wordpress

查看:32
本文介绍了获取,修改,然后在 wordpress 中打印帖子标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在wordpress中是否有一种本地方式可以使scentence的第一个单词的第一个字母大写/帖子的标题?

Is there a way native way in wordpress to make uppercase the first letter of the first word of the scentence / the_title of the post?

如果没有,当它被包裹在 <a></a> 标签中时,我如何在 php 中做到这一点?

If not, how do I do it in php, while it is wrapped in a <a></a> tag?

这是完整的代码行.

<a href="<?php the_permalink(); ?>"><?php ucfirst(the_title());?></a>

如您所见,我尝试了 ucfirst,但它不起作用.我尝试的另一件事是:

As you see, I have tried ucfirst, but it does not work. The other thing that I tried is:

<?php
$temp_title  = the_title();
$final_title = ucfirst($temp_title);
?>
<a href="<?php the_permalink(); ?>"><?php echo $final_title;?></a>

推荐答案

ucfirst() 返回一个字符串.您需要 echoucfirst() 返回的值.

ucfirst() returns a string. You need to echo the value returned from ucfirst().

此外,WordPress 函数 the_title() 直接打印标题,而不是将其作为字符串返回.改用 get_the_title().

Furthermore, the WordPress function the_title() prints the title directly, rather than returning it as a string. Use get_the_title() instead.

<a href="<?php the_permalink(); ?>"><?php echo ucfirst(get_the_title());?></a>

这篇关于获取,修改,然后在 wordpress 中打印帖子标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆