Archived topic
Different menu, logo, link on specific page and category
31 replies · Started by Royal Rangers on October 23, 2020
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?
Hi, 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/Iun2
Other 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/PTpX
Sorry for my bad english.
You 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.
Works. Thanks a lot. Awesome support.
Good to know. No problem. :)
Sorry 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.
It 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/
Thanks for quick reply. Amazing...
I have these filters which works
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_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.
Perhaps this $args['menu'] = '757'; part is wrong.
Can you verify if you're using the right menu ID?
ID 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.
That'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.
I 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
This .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>';
}
});
Yes, 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.
You 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>';
}
});