Last active
March 8, 2017 06:02
-
-
Save gatespace/dba61ddcb8a0f238e60a839cb87d24fc to your computer and use it in GitHub Desktop.
WordPress カスタム投稿タイプのアーカイブをカスタムメニューで追加してCSSクラスもいい感じに付与 ref: http://qiita.com/gatespace/items/163e42019c40d7f1b01a
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function my_special_nav_class( $classes, $item ) { | |
| // カスタム投稿タイプ special の投稿が表示されてる時カスタム投稿タイプアーカイブがメニューにあればCSSクラスを追加。 | |
| if ( is_singular( 'special' ) && $item->type === 'post_type_archive' && $item->object === 'special' ) { | |
| if ( ! in_array( 'current-post-ancestor', $classes ) ) { | |
| $classes[] = 'current-post-ancestor'; | |
| } | |
| } | |
| return $classes; | |
| } | |
| add_filter( 'nav_menu_css_class', 'my_special_nav_class', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment