回答:
ドキュメントはありませんが、次のthe_titleようなフィルターを常に適用できます。
add_filter('the_title','some_callback');
function some_callback($data){
global $post;
// where $data would be string(#) "current title"
// Example:
// (you would want to change $post->ID to however you are getting the book order #,
// but you can see how it works this way with global $post;)
return 'Book Order #' . $post->ID;
}
これらを参照してください:
if ($post->ID == 45) { ... }
the_titleフィルターは、Wordpressの最新バージョンでは機能しなくなり、他の回答で詳しく説明されているように使用document_title_partsまたはpre_get_document_titleフィルターします。
Wordpress 4.4では、Wordpressフィルターdocument_title_partsを使用してタイトルを変更できます。
以下を追加しますfunctions.php。
add_filter('document_title_parts', 'my_custom_title');
function my_custom_title( $title ) {
// $title is an array of title parts, including one called `title`
$title['title'] = 'My new title';
if (is_singular('post')) {
$title['title'] = 'Fresh Post: ' . $title['title'];
}
return $title;
}
the_title()とget_the_title()関数の動作を変更するため、パラメーターを渡す必要はありません。
文書のtitle属性を変更したい人のために、wp_titleフィルターの使用はもはや機能しないことがわかりました。代わりに、pre_get_document_titleフィルターを使用します:
add_filter("pre_get_document_title", "my_callback");
function my_callback($old_title){
return "My Modified Title";
}
現在のページのカスタムタイトル(つまり、 <title></title>ヘッダータグ)を表示するか、ページ本文またはリストでページのタイトルをフィルター処理するかは、。
前者の場合(現在のページのタイトル)、次のwp_title()ようなフィルターを追加してみてください:http :
//codex.wordpress.org/Plugin_API/Filter_Reference/wp_title
全面的にページタイトルを変更したい場合、フィルタリングthe_title()はトリックを行います:http :
//codex.wordpress.org/Plugin_API/Filter_Reference/the_title
wp_titleとthe_titleの両方をカバーします。
ページごとにタイトルを変更したいですか?最初に、カスタム投稿がボックスに合うようにセットアップしました。Smashing Magazineが最近取り上げました:http : //wp.smashingmagazine.com/2011/10/04/create-custom-post-meta-boxes-wordpress/。次に、カスタムメタボックスに値がある場合、タイトルを置き換える単純な関数を作成できます。
この機能も提供するいくつかのSEOプラグインがあります。例としてYoast SEOを試してください: http
お役に立てれば。