【问题标题】:Function to Change Page Title In Wordpress在 Wordpress 中更改页面标题的功能
【发布时间】:2014-12-09 20:22:23
【问题描述】:

我正在使用以下函数来更改 wordpress 中的页面标题。它适用于单个页面 (page.php),但不适用于我的静态主页或单个帖子 (single.php)。

我需要进行哪些更改才能在整个网站上进行这项工作?

<?php


function wpse46249_filter_wp_title( $title ) {

    $some_custom_title_content = 'This is added to title';

    $custom_title = $title . $some_custom_title_content;

    return $custom_title;
}
add_filter( 'wp_title', 'wpse46249_filter_wp_title' );
?>

【问题讨论】:

  • 你想为所有帖子设置相同的页面标题吗?
  • @HelpingHands,没有。该代码在传入的原始$title 上附加了一些内容。
  • @user1609391...这听起来像是模板问题。
  • 你能粘贴在single.php上打印title的代码

标签: wordpress function page-title


【解决方案1】:
function wpse46249_filter_wp_title( $title ) {

    $some_custom_title_content = 'This is added to title';

    $custom_title = $title . $some_custom_title_content;

    return $custom_title;
}
add_filter( 'the_title', 'wpse46249_filter_wp_title' );

请注意标题保存在 wp_posts 表中。您在上面使用的过滤器将更改所有正在保存的新帖子标题。此过滤器只是在从数据库中提取标题后修改标题,实际上并没有更改数据库值。

也只适用于调用 the_title() 的页面。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-08
    • 1970-01-01
    • 2012-12-12
    相关资源
    最近更新 更多