Modifying wp_head (2 posts)

  1. mituls
    Posted 7 years ago #

    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,


  2. nmac
    Posted 6 years ago #

    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.


Topic Closed

This topic has been closed to new replies.

About this Topic