[Resolved] Need to set a different URL for each different header logo

Home Forums Support [Resolved] Need to set a different URL for each different header logo

Home Forums Support Need to set a different URL for each different header logo

Viewing 15 posts - 1 through 15 (of 21 total)
  • Author
    Posts
  • #603222
    Rachael

    Hi, I am using different headers which each have a different site logo in them. I managed to set one of them to link back to the ‘homepage’ of that particular section (using the same header and logo). BUT, it changes it for all of the headers and logos. So, how can I set it for each different header?

    I have this script in my hook wp_footer:
    <script>
    jQuery(document).ready(function($) {
    var mobile, widthTimer;
    mobile = jQuery( ‘.menu-toggle’ );

    function generateMoveNav() {
    if ( mobile.is( ‘:visible’ ) ) {
    jQuery(‘.main-navigation’).insertBefore(‘.site-logo’);
    } else {
    jQuery(‘.main-navigation’).insertAfter(‘.site-logo’);
    }
    }

    if ( mobile.is( ‘:visible’ ) ) {
    generateMoveNav();
    }

    jQuery(window).resize(function() {
    clearTimeout(widthTimer);
    widthTimer = setTimeout(generateMoveNav, 100);
    });
    });
    </script>

    And this in functions:
    add_filter( ‘generate_sections_sidebars’,’generate_enable_sections_sidebars’ );
    function generate_enable_sections_sidebars()
    {
    return true;
    }

    add_filter( ‘generate_logo_href’,’generate_add_custom_logo_href’ );
    function generate_add_custom_logo_href()
    {
    if ( is_page( ‘erg-services’ ) ) {
    return ‘http://test.ergapc.co.uk/erg-services/&#8217;;
    }

    return ‘http://test.ergapc.co.uk/erg-services/&#8217;;
    }

    It enables the logo to link back to that specific URL. But when I’m on a different page with a different header and logo, how can I also get it to link to a different URL for pages that use that header only? Basically, how can I duplicate that code but make it work for a specific header? Thanks.

    #603705
    Leo
    Staff
    Customer Support

    Hi there,

    No JS should be required

    Looks like you are already using the correct filter:
    https://docs.generatepress.com/article/generate_logo_href/

    But if you have both return to the same URL.

    The URL inside the if statement should be the specific URL that you want that page to return to.

    The URL at the end is for general return link.

    Let me know if this helps.

    #604163
    Rachael

    It is now:
    add_filter( ‘generate_logo_href’,’generate_add_custom_logo_href’ );
    function generate_add_custom_logo_href()
    {
    if ( is_page( ‘/erg-services/’ ) ) {
    return ‘/erg-services/’;
    }

    return ‘http://test.ergapc.co.uk/&#8217;;

    }
    But it does not work. Any suggestions please? Thanks.

    #604385
    Heiko

    Hello!

    What about if ( is_page( 'erg-services' ) ) {
    instead of if ( is_page( β€˜/erg-services/’ ) ) { ?

    Best regards,
    Heiko

    #604509
    Leo
    Staff
    Customer Support

    Yup the first notation is the correct one πŸ™‚

    #604917
    Rachael

    Thank you. But it now says “nonce_failure”. and does not work. I simply want each different logo in each corresponding header to be able to link to a different section using each corresponding header. Please can someone help with this?

    #604918
    Rachael

    Update – it was caching. So it does work if I am on http://test.ergapc.co.uk/erg-services/ but if I click anywhere else within that section that is using that specific header, such as this page: http://test.ergapc.co.uk/erg-services/thermal/thermal-oxidisers/, it reverts to linking back to the main page which is http://test.ergapc.co.uk/. I need all of the pages that use a specific header to link to that ‘homepage’ of the section using that specific header.

    Does this explain it better?
    I have three different logos in three different headers. On the pages that use each of those different headers, I need the logo in each header to link to the ‘homepage’ for each section. So, when the user is on any of the pages within http://test.ergapc.co.uk/erg-services/ such as http://test.ergapc.co.uk/erg-services/thermal/thermal-oxidisers/ the logo in the header needs to link to http://test.ergapc.co.uk/erg-services/. If the user is on the maintenance page http://test.ergapc.co.uk/erg-maintenance/, I need the logo to link to http://test.ergapc.co.uk/erg-maintenance/ and if the user is on the main homepage of the entire site http://test.ergapc.co.uk then I need the logo to link to http://test.ergapc.co.uk (which it does do that now). The most important thing is for the logo in the /erg-services/ header to link to http://test.ergapc.co.uk/erg-services/ when in any of those pages using that header. Is there anyone who can help with this? Thanks.

    #604962
    Heiko

    Maybe you should hire someone with coding skills. πŸ™‚ Try this one:

    add_filter( 'generate_logo_href','hm_generate_add_custom_logo_href' );
    function hm_generate_add_custom_logo_href()
    {
        if ( is_page( 'erg-services' ) ) {
            return 'http://test.ergapc.co.uk/erg-services/';
        }
        else if ( is_page( 'erg-maintenance' ) ) {
            return 'http://test.ergapc.co.uk/erg-maintenance/';
        }
        else if ( is_page( '...' ) ) {
            return 'http://test.ergapc.co.uk/...';
        }
        else return 'http://test.ergapc.co.uk/';
    }
    
    #604963
    Rachael

    Well, I thought that was one of the reasons this support forum exists for Generate Press members. Thank you for that. I will try it out!

    #605025
    Heiko

    I thought that this would save you a lot of time. πŸ™‚

    Indeed, the customer service here is extraordinary great, because they even answer questions which do not belong to GeneratePress itself and help wherever they can.

    #605030
    Rachael

    Yes absolutely! It’s amazing support! What would help is if we could specify the logo URL link within each header in the Generate Press theme customization section.

    The following is now working on every page apart from the main page http://test.ergapc.co.uk/ where it is linking to http://test.ergapc.co.uk/erg-services/ and should link to http://test.ergapc.co.uk/

    add_filter( ‘generate_logo_href’,’generate_add_custom_logo_href’ );
    function generate_add_custom_logo_href()
    {
    if ( is_page( ‘http://test.ergapc.co.uk&#8217;) ) {
    return ‘http://test.ergapc.co.uk&#8217;;
    }
    else if ( is_page( ‘erg-maintenance’ ) ) {
    return ‘http://test.ergapc.co.uk/erg-maintenance/&#8217;;
    }

    else if ( is_page( ‘…’ ) ) {
    return ‘http://test.ergapc.co.uk/erg-services/…&#8217;;
    }
    else return ‘http://test.ergapc.co.uk/erg-services/&#8217;;
    }

    #605322
    Heiko

    And why did you not use my code? With else return β€˜http://test.ergapc.co.uk/erg-services/’; you specify the “rest” of your site which do not match the ones from your if-statements before. So this should be as in my code before. If you want to test your starpage, you can use is_home() instead of is_page(). The example is_page('...') was only a placeholder and should be changed or removed by you if you do not need another condition.

    #605393
    Rachael

    I did try your code first and it didn’t work. None of the pages within /erg-services/ (which is the bulk of the site) linked to /erg-services/. They all linked back to http://test.ergapc.co.uk which isn’t right.

    Now, everything is correct apart from when you are on http://test.ergapc.co.uk main page. That logo links to /erg-services/ and should either not link at all or simply link to http://test.ergapc.co.uk.

    Sorry about the confusion. It’s nearly there. Thanks for your help.

    #605398
    Leo
    Staff
    Customer Support

    The last line:
    else return 'http://test.ergapc.co.uk/erg-services/';

    should be
    else return 'http://test.ergapc.co.uk';

    #605415
    Rachael

    Thank you Leo but nope. That doesn’t work. It cause pages like this http://test.ergapc.co.uk/erg-services/water/odour-control/ to link back to http://test.ergapc.co.uk. All pages like that (that are under /erg-services/…) need the logo to link back to http://test.ergapc.co.uk/erg-services/

Viewing 15 posts - 1 through 15 (of 21 total)
  • You must be logged in to reply to this topic.