前提・実現したいこと
googleの検索結果などに出てくる際の記事ページのページタイトルにセパレーターを表示させたい。
使用テーマ:http://lionmedia.fit-jp.com/
wpバージョン:4.9.3
発生している問題・エラーメッセージ
googleの検索結果などに出てくる際の記事ページのページタイトルですが、現在は以下のような表示になっています。
「記事のタイトル 半角スペース サイト名」
この半角スペースを「|」に変えようと思い以下のコードを小テーマのfunction.phpに追記しました。
// タイトルのセパレータ function change_separator() { return "|"; // ここに変更したい区切り文字を書く } add_filter('document_title_separator', 'change_separator');
参考サイト:https://joyplot.com/documents/2016/09/07/wordpress-title-separator/
しかし、記事ページのタイトルタグには反映されるのですが、googleの検索結果に表示されるタイトルには反映されません。
検索結果のほうにも反映させるにはどうしたらいいでしょうか、、ご教授お願いします。
小テーマのfunction.php全て
<?php ////////////////////////////////////////////////// //親テーマstyle.cssを読み込む ////////////////////////////////////////////////// function fit_head_child() { if ( get_option('fit_seo_cssLoad-main')) { echo '<link class="css-async" rel href="'.get_template_directory_uri().'/style.css">'."\n"; }else{ echo '<link rel="stylesheet" href="'.get_template_directory_uri().'/style.css">'."\n"; } } add_action('wp_head', 'fit_head_child'); ////////////////////////////////////////////////// //下記ユーザーカスタマイズエリア ////////////////////////////////////////////////// // トップページの記事の説明文が規定文字数オーバーした時に表示される三点リーダーを任意の文字に変更 // returnに戻り値として与えてあげる function my_excerpt_more($more) { return '…'; } add_filter('excerpt_more', 'my_excerpt_more'); // 下層ページ 上部の見出し function fit_archive_title__child() { $title = get_bloginfo( 'name' ); if ( is_category() ) { $title = '「'. single_cat_title( '', false ) . '」カテゴリーの記事一覧'; } elseif ( is_tag() ) { $title = '「'. single_tag_title( '', false ) . '」タグの記事一覧'; } elseif ( is_author() ) { $title = '「'. get_the_author() . '」が投稿した記事一覧'; } elseif ( is_year() ) { $title = '「'. get_the_date('Y年') . '」に投稿された記事一覧'; } elseif ( is_month() ) { $title = '「'. get_the_date('Y年n月') . '」に投稿された記事一覧'; } elseif ( is_day() ) { $title = '「'. get_the_date('Y年n月j日') . '」に投稿された記事一覧'; } elseif ( is_search() ) { $title = '「'.get_search_query().'」の検索結果:' ; } elseif ( is_404() ) { $title = 'お探しのページは見つかりませんでした(404エラー)' ; } return $title; } // js読み込み function my_scripts_method() { wp_enqueue_script( 'custom-script', get_stylesheet_directory_uri().'/js/custom.min.js', array( 'jquery' ), '1.0', true ); } add_action( 'wp_enqueue_scripts', 'my_scripts_method' ); // ビジュアエディタにカスタマイズしたcssを反映させる add_editor_style('style-editor.css'); remove_filter('the_title', 'wptexturize'); remove_filter('the_content', 'wptexturize'); remove_filter('the_excerpt', 'wptexturize'); // タイトルのセパレータ function change_separator() { return "|"; // ここに変更したい区切り文字を書く } add_filter('document_title_separator', 'change_separator');
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/08/31 01:12