- This topic has 31 replies, 3 voices, and was last updated 3 years, 4 months ago by Elvin.
-
AuthorPosts
-
October 27, 2020 at 9:02 am #1506611LeoStaffCustomer Support
Looks like Elvin’s code is working but maybe we are misunderstanding what you want.
Where do you want the logo on the
/blog
page link to?October 27, 2020 at 1:07 pm #1506952Royal RangersHi, default logo link is royalranges.cz
On specific pages I need customized link – royalrangers.cz/ringoturnaj It´s work with this code:add_filter( 'generate_logo_href', function() { if ( is_page( array(14901,15068,15058,15060,15062,15066,15064,15070,15072,15056,14916,15074,15076) ) || is_category('ringoturnaj') ) return "https://www.royalrangers.cz/ringoturnaj/"; } );
For example:
https://ctrlv.cz/kJ8c
https://ctrlv.cz/Iun2Other sites I need a default logo link but it doesn´t work. Link is on same page where I am. I need a link for homepage – royalrangers.cz
For example:
https://ctrlv.cz/hYK1
https://ctrlv.cz/PTpXSorry for my bad english.
October 27, 2020 at 5:22 pm #1507093ElvinStaffCustomer SupportYou can try this out.
add_filter( 'generate_logo_href', function() { if ( is_page( array(14901,15068,15058,15060,15062,15066,15064,15070,15072,15056,14916,15074,15076) ) || is_category('ringoturnaj') ){ return "https://www.myweb.cz/ringoturnaj/"; } else { return home_url( '/' ); } }, 25 );
We basically just set the condition for logo href in a way where if it’s not on the specified pages it will return the default
home('/')
for every other pages.October 27, 2020 at 9:44 pm #1507207Royal RangersWorks. Thanks a lot. Awesome support.
October 28, 2020 at 12:54 pm #1508465ElvinStaffCustomer SupportGood to know. No problem. 🙂
November 4, 2020 at 2:21 pm #1518312Royal RangersSorry for re-open.
It is possible to use these settings for archive category page and to posts from this category.
Example for different primary menu I tried:
add_filter( 'wp_nav_menu_args', 'ringoturnaj_primary' ); function ringoturnaj_primary( $args = '' ) { // change the menu in the Header menu position if( $args['theme_location'] == 'primary' && is_page( array(14901,15068,15058,15060,15062,15066,15064,15070,15072,15056,14916,15074,15076,15697,15695,15693) ) || is_category('759') || is_post_type_archive( 'aktuality-z-ringoturnaje' )) { $args['menu'] = '756'; } return $args; }
On archive category page it works. On post doesn´t work.
I´m sorry for the complicated explanation.November 4, 2020 at 2:30 pm #1518314ElvinStaffCustomer SupportIt is possible to use these settings for archive category page and to posts from this category.
100% possible.
On archive category page it works. On post doesn´t work.
It doesn’t work on posts because you didn’t add the condition to include posts.
You have to add something like this –
|| ( is_single() && in_category( 'ringoturnaj' ) )
– in your condition.is_single()
checks if the page is a single post,in_category()
checks if the page is in the specified category.That said, your condition should look something like this:
if( $args['theme_location'] == 'primary' && is_page( array(14901,15068,15058,15060,15062,15066,15064,15070,15072,15056,14916,15074,15076,15697,15695,15693) ) || is_category('759') || is_post_type_archive( 'aktuality-z-ringoturnaje' ) || ( is_single() && in_category( 'ringoturnaj' ) ) )
References:
https://developer.wordpress.org/reference/functions/in_category/
https://developer.wordpress.org/reference/functions/is_single/November 4, 2020 at 3:11 pm #1518345Royal RangersThanks for quick reply. Amazing…
I have these filters which worksadd_filter( 'wp_nav_menu_args', 'ringoturnaj_primary' ); function ringoturnaj_primary( $args = '' ) { // change the menu in the Header menu position if( $args['theme_location'] == 'primary' && is_page( array(14901,15068,15058,15060,15062,15066,15064,15070,15072,15056,14916,15074,15076,15697,15695,15693) ) || is_category('759') || ( is_single() && in_category( '759' ) )) { $args['menu'] = '756'; } return $args; }
add_filter( 'wp_nav_menu_args', 'ringoturnaj_slideout' ); function ringoturnaj_slideout( $args = '' ) { // change the menu in the Header menu position if( $args['theme_location'] == 'slideout' && is_page( array(14901,15068,15058,15060,15062,15066,15064,15070,15072,15056,14916,15074,15076,15697,15695,15693) ) || is_category('759') || ( is_single() && in_category( '759' ) )) { $args['menu'] = '758'; } return $args; }
This filter does not show a secondary menu but a primary menu. What´s wrong? Everything is same.
add_filter( 'wp_nav_menu_args', 'ringoturnaj_secondary' ); function ringoturnaj_secondary( $args = '' ) { // change the menu in the Header menu position if( $args['theme_location'] == 'secondary' && is_page( array(14901,15068,15058,15060,15062,15066,15064,15070,15072,15056,14916,15074,15076,15697,15695,15693) ) || is_category('759') || ( is_single() && in_category( '759' ) )) { $args['menu'] = '757'; } return $args; }
In CSS I try adding
.category-aktuality-z-ringoturnaje .sticky-navigation-logo, .single-post.category-aktuality-z-ringoturnaje .sticky-navigation-logo { display: none !important; }
Category works. Single post of category don´t work.
November 4, 2020 at 3:24 pm #1518352ElvinStaffCustomer SupportPerhaps this
$args['menu'] = '757';
part is wrong.Can you verify if you’re using the right menu ID?
November 4, 2020 at 3:34 pm #1518355Royal RangersID is correct. Other pages with defined ID are fine. Only
|| is_category('759') || ( is_single() && in_category( '759' )
is wrong for secondary menu. Primary and slideout menu is fine with same filter.November 4, 2020 at 5:31 pm #1518422ElvinStaffCustomer SupportThat’s strange.
If the condition worked for the other two menu locations, it should be the same w/ this one as well.
To clarify and get the whole picture of what you’re trying to do:
Are you trying to change the primary, secondary and slideout menu for the specified category archive page, specified single posts under the specified category and some specified pages?
If so, you can just add them all in one snippet.
Something like this should work:
add_filter( 'wp_nav_menu_args', 'ringoturnaj_menu_change' ); function ringoturnaj_menu_change( $args ) { // change the menu in the Header menu position if( is_page( array(14901,15068,15058,15060,15062,15066,15064,15070,15072,15056,14916,15074,15076,15697,15695,15693) ) || is_category('759') || ( is_single() && in_category( '759' ) ) ) { if($args['theme_location'] == 'primary'){ $args['menu'] = 'menu id for primary'; } if($args['theme_location'] == 'secondary'){ $args['menu'] = 'menu id for secondary'; } if($args['theme_location'] == 'slideout'){ $args['menu'] = 'menu id for slideout'; } } return $args; }
Just change the menu id values.
November 4, 2020 at 9:07 pm #1518485Royal RangersI don’t get it but this filter works!
Last thing. In CSS I have this for disale default sticky logo.
.page-id-14901 .sticky-navigation-logo, .page-id-15068 .sticky-navigation-logo, .page-id-15058 .sticky-navigation-logo, .page-id-15060 .sticky-navigation-logo, .page-id-15062 .sticky-navigation-logo, .page-id-15066 .sticky-navigation-logo, .page-id-15064 .sticky-navigation-logo, .page-id-15070 .sticky-navigation-logo, .page-id-15072 .sticky-navigation-logo, .page-id-15056 .sticky-navigation-logo, .page-id-14916 .sticky-navigation-logo, .page-id-15074 .sticky-navigation-logo, .page-id-15076 .sticky-navigation-logo, .page-id-15697 .sticky-navigation-logo, .page-id-15695 .sticky-navigation-logo, .page-id-15693 .sticky-navigation-logo, .category-aktuality-z-ringoturnaje .sticky-navigation-logo, .single-post.category-aktuality-z-ringoturnaje .sticky-navigation-logo { display: none !important; }
Everything works except .single-post.category
https://ctrlv.cz/dVs5
November 4, 2020 at 9:39 pm #1518497ElvinStaffCustomer SupportThis
.category-aktuality-z-ringoturnaje
doesn’t seem to be in use by any of.sticky-navigation-logo
‘s ancestor elements.That said, try this:
We can apply the CSS using PHP snippets as well.
add_action( 'wp_head', function () { if( is_page( array(14901,15068,15058,15060,15062,15066,15064,15070,15072,15056,14916,15074,15076,15697,15695,15693) ) || is_category('759') || ( is_single() && in_category( '759' ) ) ){ echo '<style> .sticky-navigation-logo{ display: none !important; } </style>'; } });
November 5, 2020 at 12:24 am #1518586Royal RangersYes, it works.
But why doesnť work simillar code for .site-info?add_action( 'wp_footer', function () { if( is_page( array(14901,15068,15058,15060,15062,15066,15064,15070,15072,15056,14916,15074,15076,15697,15695,15693) ) || is_category('759') || ( is_single() && in_category( '759' ) ) ){ echo '<style> .site-info{ color: #ffffff; background-color: #617e2a; } </style>'; } });
I try did with wp_head and wp_footer.
November 5, 2020 at 12:34 pm #1519670ElvinStaffCustomer SupportYou can add the
.site-info{ color: #ffffff; background-color: #617e2a;
within the<style> ... </style>
of the code I provided so we don’t have too many snippets to check on.Something like this:
add_action( 'wp_head', function () { if( is_page( array(14901,15068,15058,15060,15062,15066,15064,15070,15072,15056,14916,15074,15076,15697,15695,15693) ) || is_category('759') || ( is_single() && in_category( '759' ) ) ){ echo '<style> .sticky-navigation-logo{ display: none !important; } .site-info{ color: #ffffff; background-color: #617e2a; } </style>'; } });
-
AuthorPosts
- You must be logged in to reply to this topic.