Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary classes #3

Closed
billerickson opened this issue Jul 20, 2016 · 1 comment
Closed

Remove unnecessary classes #3

billerickson opened this issue Jul 20, 2016 · 1 comment

Comments

@billerickson
Copy link
Owner

Specifically on body_class, post_class, and nav_menu_css_class

Right now with Leites on Pagely we keep going over bandwidth limits, so I’ve been analyzing stuff. They have a fairly moderate to large primary navigation (lots of dropdowns etc). So, I filtered to remove all the BS classes on the nav items except "current-menu" type classes. Since nav is on every page of the site, doing that made the HTML page size go down 5+ kb globally. 5kb over an average of 8 million page views a month translates to ​_40 gigs_​ saved in bandwidth per month…. 😮 which is 20% of the monthly bandwidth allotment

@jaredatch
Copy link
Collaborator

This needs to be tweaked more, since this is more or less a straight adaption from StackOverflow, but you get the gist.

function lc_clean_wp_nav_menu($var) {

    return is_array( $var ) ? array_intersect( $var, array(
        //  'menu-item',
            'current_page_item',
            'current_page_parent',
            'current_page_ancestor',
            )
    ) : '';
}
add_filter('nav_menu_css_class', 'lc_clean_wp_nav_menu');
add_filter('nav_menu_item_id', 'lc_clean_wp_nav_menu');
add_filter('page_css_class', 'lc_clean_wp_nav_menu');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants