[Resolved] Slow database query when using mobile header logo

Home Forums Support [Resolved] Slow database query when using mobile header logo

Home Forums Support Slow database query when using mobile header logo

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2426423
    Dan

    Hi, I see a slow database query when I set a logo in the Mobile Header via the customiser – customiser -> layout -> header -> mobile header -> logo. The query is adding 0.5 of a second to each page load on average. The image it’s selecting is a well-optimised PNG, I’ve also tried a 1kb SVG with the same results.

    Screenshot of the query: https://capture.dropbox.com/L0q1onQHYAH5K30y

    How can this query be better optimised?

    #2428223
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    We’re aware of the attachment_url_to_postid() issues in WP, but it certainly shouldn’t be taking that long.

    We’re working on a solution so we can ditch that function completely in the next GPP.

    For now, you can tell our function not to run and add your own.

    You’ll just need to manually enter the image width/height.

    add_action( 'after_setup_theme', function() {
        remove_action( 'generate_inside_mobile_header', 'generate_menu_plus_mobile_header_logo', 5 );
    
        add_action( 'generate_inside_mobile_header', function() {
            $settings = wp_parse_args(
                get_option( 'generate_menu_plus_settings', array() ),
                generate_menu_plus_get_defaults()
            );
    
            $image_width = '100'; // Your image width.
            $image_height = '100'; // Your image height.
    
            printf(
                '<div class="site-logo mobile-header-logo">
                    <a href="%1$s" title="%2$s" rel="home">
                        <img src="%3$s" alt="%4$s" class="is-logo-image" width="%5$s" height="%6$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' ) ) ),
                ! empty( $image_width ) ? absint( $image_width ) : '',
                ! empty( $image_height ) ? absint( $image_height ) : ''
            );
        }, 5 );
    } );

    I’ve made sure to log this issue so it gets fixed in GPP 2.3.0.

    Thanks!

    #2429895
    Dan

    Thank you, Tom. Nice solution!

    #2431793
    Tom
    Lead Developer
    Lead Developer

    Glad I could help! 🙂

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