Change dns-prefetch to preconnect for external enqueued resources

There’s a filter, wp_resource_hints, but it only filters each “relation type” (i.e. preconnect, dns-prefetch, etc.) individually, rather than the whole $hints array in your question. However, you could use the filter to empty the array for dns-prefetch and add wp_resource_hints_scripts_styles() to the preconnect array, like this: add_filter( ‘wp_resource_hints’, function( $urls, $relation_type ) { if ( … Read more

wp_head() outputs in body

This is your browser’s attempt to avoid invalid markup. Your echo ‘ test’; outputs something that does not belong in a head tag, so the browser closes it and opens the body tag. If you look at the actual unprocessed response from the server, it won’t appear this way, but that echo shouldn’t be there … Read more

How to remove pingback from head?

Here’s my improvement on it with less code for the same results: add_action( ‘plugins_loaded’, ‘wpse_158700_buffer’ ); function wpse_158700_buffer() { # Enable output buffering ob_start( ‘wpse_158700_pingback_url’ ); } function wpse_158700_pingback_url( $buffer ) { # If in the admin panel, don’t run if ( is_admin() && ( ! defined( ‘DOING_AJAX’ ) || ! DOING_AJAX ) ) { … Read more

Multi-page posts do not get indexed by Google due to canonical URLs

You will need to replace the default rel_canonical function to do this: function wpse_84647_rel_canonical() { /* Only affect singular posts. Exit early if Yoast SEO is doing this for us */ if ( ! is_singular() || class_exists( ‘WPSEO_Frontend’ ) ) return; /* Get the post permalink */ $post = get_queried_object(); $link = trailingslashit( get_permalink( $post->ID … Read more

Is there a way to read or list wp_head() contents?

I wanted to search-and-replace in the header, but Neither @majick or @Samuel Elh answers worked for me directly. So, combining their answers I got what eventually works: function start_wp_head_buffer() { ob_start(); } add_action(‘wp_head’,’start_wp_head_buffer’,0); function end_wp_head_buffer() { $in = ob_get_clean(); // here do whatever you want with the header code echo $in; // output the result … Read more

How can i get the name parameter defined in get_header?

There is an action get_header that you can use. In your theme’s functions.php, register a callback for that action: add_action( ‘get_header’, function( $name ) { add_filter( ‘current_header’, function() use ( $name ) { // always return the same type, unlike WP return (string) $name; }); }); You could also write a little helper class that … Read more

WordPress Code Flow

Probably the Program Flow on ToolPress is something for you: WordPress 3.0 Program Flow File Inclusions (Default Request); PDF. Contains important filenames, constants and hooks. My Favorite Cheat Sheet so far for the code flow stuff.