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 unless you want to remove it
}
add_action('wp_head','end_wp_head_buffer', PHP_INT_MAX); //PHP_INT_MAX will ensure this action is called after all other actions that can modify head
It was added to functions.php
of my child theme.
Related Posts:
- WordPress Code Flow
- How can i get the name parameter defined in get_header?
- Multi-page posts do not get indexed by Google due to canonical URLs
- Remove rel=’dns-prefetch’ href=’//maps.google.com’ from wp-head
- How to remove pingback from head?
- wp_head() outputs in body
- Change dns-prefetch to preconnect for external enqueued resources
- How to remove unnecessary elements in the HTML document head
- wp_head() not including styles and javascripts after a template redirect
- Removing Visual Composer head meta (works alone but not with IF)
- removing wordpress generated code from the head section?
- Change default s.w.org dns-prefetch resource hint value
- using wp_head in body tag for css style
- Use wp-load() and wp_head() to render a page’s header outside of WordPress
- Set title of page using custom page template
- How do I add a logo to my website?
- Set up description meta automatically
- How to find which plugin is outputting Open Graph tags to
- Why would wp_head() cause the menus to break?
- wp_head function outputs after
- Remove_action inside a function
- Does adding a callback like this to wp_head allows you to add additional content?
- How can i remove JUST Description tag from wp_head() function?
- Custom page with WP Header showing Page not found title
- Getting the contents of wp_head while in admin?
- Wp_head () affecting my images layout
- How to add meta tags inside single image page?
- How to store wordpress functions (wp_head(),wp_footer()) in a javascript variable?
- “Warning: count()” printing in Page templates
- How can I edit a meta description
- Hide page name in wordpress page title
- Is it possible to add post specific info in head of worpress post for OG use
- Unable to apply selective loading
- why php tag is not working if i store and show it in wp_head?
- output specific location in the header
- Data validation for inline javascript
- Add OG meta tags to wp head
- Add tags to the section via functions.php
- Why is wp_head() creating a top margin at the top of my theme header?
- How to add stylesheets only to pages with specific shortcode?
- What does l10n.js do in WordPress 3.1? And how do I remove it?
- How do I force wp_enqueue_scripts to load at the END of ?
- How can I modify what is being output in wp_head, whether by a theme or WordPress in general?
- How to control initial wp_head() output?
- Modify page title format (when using title-tag)
- How to load different css file for different pages
- Track down where script is being enqueued from
- append stylesheet via shortcode
- Remove specific CSS and JS from the head
- How to load plugin before the wordpress jquery?
- Manipulating wp_head content
- Disable wordpress from including jQuery in the head section
- wp_head() not inserting the default stylesheet style.css
- Deregister CSS style link ‘open-sans-css’
- Filter out some plugin action in wp head / wp_footer
- add_action and wp_head not display content in head section
- Header has extra HTML block at top before my code
- Trying to inject twitter metadata into using wp_head action in functions.php – get_the_excerpt() returns null
- Replace category titles
- Remove Genericons Helper CSS from twentyfourteen theme
- How do I edit wp_head and/or functions.php to remove rss-feed which isnt used and dont validate?
- How To Make Sure That My Action Hook Executes Last
- adding meta data using plugin to top of head
- Remove meta description on certain pages
- Get latest posts from WordPress site without header, menu and sidebar
- Add javascript to wp_head with call to plugin options?
- CSS from textarea in options page to frontend what to do
- Edit title-tag in wp_head with yoast seo
- How to preload images through Code Snippets wp_head for specific pages?
- Add head and body function for google tag manager in child theme
- What is the safe way to print tracking code / pixel code before tag or tag
- How to modify default controls in WordPress theme customizer
- How to replace a function using a child theme?
- ACF custom field in [closed]
- Would there be anything stopping me from removing both wp_head and wp_footer?
- How to customize
- Can’t find where to modify attrbitutes
- Auto Generated HTML source code formatting
- Remove tags from wordpress head
- wp_enqueue_style on template_redirect level?
- Remove CSS & JS from
- Run shortcode in custom script in wp_head if post type is CPT ‘Jobs’
- Include HTML (Bootstrap Modal Box) with a plugin into my header
- add_action to wp_head is added, but not called
- Empty lines in header, how to remove them
- Function to echo (or display?) wordpress tags in the head section
- How to remove a meta description or other contents
- Hide author info in single posts by certain users
- Add function to head “no product found”
- Load admin bar without wp_head or wp_footer [duplicate]
- Put dynamic Javascript in header after doing operations
- How do I add Facebook OpenGraph meta tags for attachments in the header for a custom theme?
- unable to override style block within wp_head()
- Background of default template showing instead of the background of custom page template
- I add some js files from a plugin to a specific location
- How to output wp_enqueue_style() in HTML head instead of footer
- new to javascript – using in instead of functions.php, not loading correctly
- Head Code for Custom Taxonomy
- Is there a way to prevent wp_head from outputting self-closing tags?
- wp_head not injecting css