特定のカテゴリまたはタグに属する投稿のみパーマリンクを変更したい
-
通常の投稿のパーマリンクは/%year%/%monthnum%/%day%/%post_id%/ の形式とし
http://hogehoge/2016/03/18/10000000/特定のカテゴリまたはタグに属する投稿の場合
/%year%/%monthnum%/%day%/%post_id%/%category%/
もしくは
/%category%/%year%/%monthnum%/%day%/%post_id%/
と設定する良い方法はありませんでしょうか?http://www.warna.info/archives/2721/ を参考にして以下のようなコードをplugin として追加してみたのですがうまく動作しないようです。
function add_article_post_permalink( $permalink ) {
if (in_category(array(‘特定のカテゴリ’)) && is_single()){
$permalink = ‘/特定のカテゴリ’ . $permalink;
}
return $permalink;
}
add_filter( ‘pre_post_link’, ‘add_article_post_permalink’ );function add_article_post_rewrite_rules( $post_rewrite ) {
if (in_category(array(‘特定のカテゴリ’)) && is_single()){
$return_rule = array();
foreach ( $post_rewrite as $regex => $rewrite ) {
$return_rule[‘特定のカテゴリ/’ . $regex] = $rewrite;
}
return $return_rule;
}
}
add_filter( ‘post_rewrite_rules’, ‘add_article_post_rewrite_rules’ );
- トピック「特定のカテゴリまたはタグに属する投稿のみパーマリンクを変更したい」には新たに返信することはできません。