I am looking to create a plugin which will allow me to update content within the wp_head function. I have the below code which is fine in allowing me to add new content during the wp_head load event;

function manipulate_head() {
        <title>This is a second title</title>

add_action('wp_head', 'manipulate_head');

However it does not allow me to remove or replace something that is already within the <head> tags on the page.

An example would be to update the <meta name="description"> tag in the section of the website. The website could have a <meta name="description"> in which case we need to update the content, otherwise we need to add a new one.

  • 3
    wp_head is an action, so anything output there is printed immediately during load, so there isn't a value to manipulate. To do this you'd need to do something very hacky to capture the output, which would prevent it being output while you do string manipulation to change the markup, therefore slowing down the site. Jun 7, 2022 at 5:39
  • 1
    If the meta description is specifically what you want to update, there are SEO plugins that let you set that value in wp-admin for various views. If there are other specific values you want to update, there are likely hooks you can use to remove or re-order what is output - it's a broad question to try to answer.
    – WebElaine
    Jun 7, 2022 at 16:26


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.