タイトルタグの書き換え(All in one seoプラグイン使用時)
マルチサイト化したサイトのfunction.php内で、
WordPressで親の親など祖先のカテゴリーを get_ancestors() で全部出力し、特定のタクソノミーの場合、All in one seoで出力しているtitleタグの書き換えをしたいです。
発生している問題・エラーメッセージ
archive.phpで下記のコードを記述するとうまくいきますが、
//現在のタームのidを取得 $term_id = get_queried_object()->term_id; //祖先タームのidを取得 $ancestors = get_ancestors( $term_id, 'my_taxonomy' ); //get_ancestors()は孫から親への順番で配列になるので、順番を入れ替える $reversed_ancestors = array_reverse($ancestors); //情報の出力 foreach($reversed_ancestors as $ancestor){ echo get_term($ancestor)->name; } `````````````` function.phpに記述するとエラーに(Arry が出力される)なります。 `````````````` function aioseop_change ($title) { if(is_tax('my_taxonomy' )){ $term_id = get_queried_object()->term_id; $ancestors = get_ancestors( $term_id, 'my_taxonomy' ); $reversed_ancestors = array_reverse($ancestors); if($ancestors){ foreach($reversed_ancestors as $ancestor){ echo get_term($ancestor)->name; } } return $reversed_ancestors; $title = $reversed_ancestors; } return $title; } add_filter('aioseop_title' ,'aioseop_change' ); flush_rewrite_rules; `````````````` ### 補足情報 実現したいことに一番近い内容 https://blog.maromaro.co.jp/archives/1788 よろしくお願いします。
あなたの回答
tips
プレビュー