在WordPress中,如何用get_the_category_by_ID()替换the_title()?
我是一位新开发人员,我刚刚在WordPress代码参考网站上阅读了the_title()已被弃用,应该使用get_the_category_by_ID。 
 问题是,我无法找到一种方法来取代它,以便它成功地在每篇博客文章上显示标题。在这些例子中,它似乎只用于类别。在WordPress中,如何用get_the_category_by_ID()替换the_title()?
有人能给我一个如何正确地做到这一点的例子吗?
回答:
您可以使用wp钩子替换标题。你可以把这个代码放在你的主题上,或者放在function.php里面。或者你的插件例如:
function my_custom_replace_title($title, $id = null) {     /* Put here your condition, you get the post ID on "$id", and the current title on "$title"*/  
    // by category 
    //if (in_category('XXX', $id)) { 
    // return ''; 
    //} 
    //if ($title === 'custom text'){ 
    // return 'this is my new title'; 
    // } 
    $title = 'My Custom Title - Forced'; // This is to test it. 
    return $title; 
} 
add_filter('the_title', 'my_custom_replace_title', 10, 2); 
我建议阅读https://codex.wordpress.org/Plugin_API/Filter_Reference/the_title
我希望帮你。
以上是 在WordPress中,如何用get_the_category_by_ID()替换the_title()? 的全部内容, 来源链接: utcz.com/qa/258730.html

