Home › Forums › Support › Adding new menu to CPT only. Are GP hooks the same in CPT? Found Visual Hooks Gu
- This topic has 3 replies, 2 voices, and was last updated 1 year, 6 months ago by
Tom.
-
AuthorPosts
-
August 16, 2019 at 12:36 pm #986025
Brad
Trying to conditionally add a menu just to CPT individual posts (not the CPT archive page though my conditional isn’t working on the archive page either). Not sure if this is possible or if my code is just incorrect. Possibly if statement is incorrect? Do I have the right GP hook? Any ideas?
Gist line 22 – 24
Thanks in advance for taking a look.
https://codex.wordpress.org/Function_Reference/is_post_type_archive
https://codex.wordpress.org/Conditional_Tags
https://gist.github.com/bradfranklin/9efe2adc4c0ed622a0cee3fb0d7aad06
August 16, 2019 at 3:45 pm #986150Tom
Lead DeveloperLead DeveloperHi there,
Yes, as long as you’re not using a custom template file with the hooks removed.
Your code itself isn’t quite right. Try this:
add_action( 'generate_after_header', function() { if ( is_post_type_archive( 'ambassadors' ) ) { wp_nav_menu( array( 'menu' => 'CPT Ambassador Menu', // Do not fall back to first non-empty menu. Was Primary Menu 'theme_location' => 'cpt-ambassador-menu', 'fallback_cb' => '__return_false' // Do not fall back to wp_page_menu() ) ); } } );
Our Elements module might be worth checking out as well, as it writes some of the above for you: https://docs.generatepress.com/article/hooks-element-overview/
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentAugust 16, 2019 at 4:09 pm #986162Brad
Sincerely, sincerely appreciate the help!! Going nuts trying different variations.
Switched out post_type_archive for is_singular to achieve objective.
if ( is_singular( ‘ambassadors’ ) ) {
Alternately was thinking about duplicating the top bar widget area, placing it with an if statement in the same area or below the menu bar instead of above, then just using the nav widget and choosing the menu of choice. All the css is taken care of with the nav widget
August 16, 2019 at 4:14 pm #986170Tom
Lead DeveloperLead DeveloperA custom menu is likely the way to go. Glad you got it working 🙂
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-development -
AuthorPosts
- You must be logged in to reply to this topic.