WordPress.org

Ready to get started?Download WordPress

Forums

Removing items from WP_Head Question (4 posts)

  1. Will D. White
    Member
    Posted 2 years ago #

    I'm in the process of cleaning up the wp_head function by adding "remove_action" filters in my functions.php file.

    There are two CSS files being loaded that I would like to remove from the wp_head queue list.

    <link rel='stylesheet' id='admin-bar-css'  href='http://example.com/wp-includes/css/admin-bar.css?ver=3.4.1' type='text/css' media='all' />
    <link rel='stylesheet' id='boxes-css'  href='http://example.com/wp-content/plugins/wordpress-seo/css/adminbar.css?ver=3.4.1' type='text/css' media='all' />

    How do I find out what to put in the remove_action() function to pull these out of the header?

    I tried putting the ID in:

    remove_action( 'wp_head', 'admin-bar-css' );
    remove_action( 'wp_head', 'boxes-css' );

    But that doesn't seem to do the trick. Any help would be appreciated.

  2. esmi
    Forum Moderator
    Posted 2 years ago #

    Why not just disable the admin bar on the front end of your site via your profile page?

  3. Will D. White
    Member
    Posted 2 years ago #

    We have multiple admins - some more savvy than others. Its a custom build and there really isn't any benefit of loading the admin bar - so we figured why load it at all. Lets pull that function out and lower the number of HTTP requests etc.

    add_filter( 'show_admin_bar', '__return_false' );

    These stylesheets became unnecessary when I removed the bar.

    Its actually not just the admin bar CSS files I'm looking to remove, either. There are a few plugins that I have running that I'm trying to figure out similar issues with. I'd love to set up an if-then statement that lets me use remove_action on plugin files when someone isn't on a page that needs them.

    For example if I only run a certain plugin on the home page, but it loads its' files on every page, I could do something like this:

    if(!is_front_page()){remove_action('wp_head','whatever-the-action-name-is');}

    However, I don't know how to find out what the name of the action is in order to get the remove_action() function to work on it.

    I hope this makes things a little clearer. Thanks for your response!

  4. Flystink
    Member
    Posted 1 year ago #

    This is an older post, but unresolved, so the answer is:
    wp-includes/default-filters.php

    Search (Ctrl+F) for wp_head and you will find the names.

Topic Closed

This topic has been closed to new replies.

About this Topic