I followed the common advise to use wp_head() in header.php and wp_enqueue_scripts() instead of hard linking css and js files in header.php.
However, I realized that wp_head() outputs lots of stuff I’m not sure if I really want it to be there. E.g. there is some CSS stylesheet stuff dealing with emotiis and smileys … for whatever reason.
//UPDATE
Despite my writing above, I am pretty aware of what parts of wp_head() I want to have in my HTML Head section.
//UPDATE II
I am developing my own theme and I have only a single plugin in use which is Pods.io.
I did some research but found solutions only that suggest to subsequently alter wp_head() output via output buffering methods (see Remove an action from an external Class). To me, that appears to be a rather dirty solution.
Hence, my question is, how can I exactly define the default output of wp_head()? What hooks are available to trigger certain output parts? Pls note, I am aware of how to add content to wp_head() via hooks but not how to precisely remove unwanted output.
Here is the current list of actions that is currently hooked by default to wp_head
Reposted here to avoid unnecessary opening multiple browser windows
add_action( 'wp_head', '_wp_render_title_tag', 1 );
add_action( 'wp_head', 'wp_enqueue_scripts', 1 );
add_action( 'wp_head', 'feed_links', 2 );
add_action( 'wp_head', 'feed_links_extra', 3 );
add_action( 'wp_head', 'rsd_link' );
add_action( 'wp_head', 'wlwmanifest_link' );
add_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );
add_action( 'wp_head', 'locale_stylesheet' );
add_action( 'wp_head', 'noindex', 1 );
add_action( 'wp_head', 'print_emoji_detection_script', 7 );
add_action( 'wp_head', 'wp_print_styles', 8 );
add_action( 'wp_head', 'wp_print_head_scripts', 9 );
add_action( 'wp_head', 'wp_generator' );
add_action( 'wp_head', 'rel_canonical' );
add_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );
add_action( 'wp_head', 'wp_site_icon', 99 );
if ( isset( $_GET['replytocom'] ) )
add_action( 'wp_head', 'wp_no_robots' );
You can remove any action with remove_action()
remove_action( 'wp_head', 'wp_print_styles, 8 );
Just remember, an action need to be removed with the same priority it was added.
As bonus, check this epic post from @ChristineCooper on how to remove emojicons
EDIT
An important note here. The foillowing actions should not be removed as this causes serious issues with how stylesheets and scripts are loaded
-
locate_stylesheet
-
wp_print_styles
-
wp_generator
-
wp_enqueue_scripts
If you need something specific removed, rather remove the call back function with remove_action
or use the specific functions allocated to remove styles and scripts