Support » Fixing WordPress » Modifying wp_head

  • Hi there,

    I am trying to modify (not add) HTML content within the <HEAD></HEAD> tags.

    Therefore, I have created a wp_head filter within the functions.php file. However, I can’t seem to get it to work correctly. Can anyone help?

    Step 1:
    Here is my function in the functions.php file:

    function mitulsdotcom_htmlCommentsStripper($content) {
    $find=”/\<![ \r\n\t]*(–([^\-]|[\r\n]|-[^\-])*–[ \r\n\t]*)\>/”;
    return $value=preg_replace($find,$replace,trim($content));


    ^ The above function takes in the content and strips of any HTML comments

    Step 2:

    Here is my filter in the functions.php file:

    add_filter(‘wp_head’, ‘mitulsdotcom_htmlCommentsStripper’);

    Any help is greatly appreciated.

    Kind regards,


Viewing 1 replies (of 1 total)
  • Hi Mitul,
    I am fairly sure that wp_head is an action hook and not a filter hook, so you cannot currently call add_filter on wp_head, just add_action.

    I may be wrong, but FWIW, check out the API Filters list in the codex.


Viewing 1 replies (of 1 total)
  • The topic ‘Modifying wp_head’ is closed to new replies.