[Resolved] Change logo URL class only on mobile

Home Forums Support [Resolved] Change logo URL class only on mobile

Home Forums Support Change logo URL class only on mobile

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1310715
    Sebastien

    Hi GP team,

    Could you please tell me how I can change the class for the logo link only on mobile devices please? I want to generate a popup whenever someone clicks on the mobile logo and for that I need to have a specific class used for the link.

    Many thanks
    Sebastien

    #1311074
    David
    Staff
    Customer Support

    Hi there,

    are you using the Mobile Header ?

    #1311075
    Sebastien

    Hi,

    Yes, I am.

    #1311119
    David
    Staff
    Customer Support
    #1311124
    Sebastien

    This is perfect, thank you. The only thing is that I do not want to rewrite the whole output just change the class for the logo link. Ideally, I could probably copy the code which is already written in the theme in this filter and add the class, would that work? Could you please give me the built in code if possible?

    Many thanks
    Sebastien

    #1311362
    David
    Staff
    Customer Support

    You need to return the entire HTML. To add a class to the <a> element you would do something like this:

    add_filter( 'generate_mobile_header_logo_output', function( $output ) {
        if ( ! function_exists( 'generate_menu_plus_get_defaults' ) ) {
            return $output;
        }
    
        $settings = wp_parse_args(
            get_option( 'generate_menu_plus_settings', array() ),
            generate_menu_plus_get_defaults()
        );
    
        return sprintf(
            '<div class="site-logo mobile-header-logo">
                <a class="your-class" href="%1$s" title="%2$s" rel="home">
                    <img src="%3$s" alt="%4$s" />
                </a>
            </div>',
            esc_url( apply_filters( 'generate_logo_href' , home_url( '/' ) ) ),
            esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) ),
            esc_url( apply_filters( 'generate_mobile_header_logo', $settings['mobile_header_logo'] ) ),
            esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) )
        );
    } );
    #1311377
    Sebastien

    Amazing, thank you 🙂

    #1311383
    David
    Staff
    Customer Support

    You’re welcome

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