Title: Modifying wp_head
Last modified: August 19, 2016

---

# Modifying wp_head

 *  [mituls](https://wordpress.org/support/users/mituls/)
 * (@mituls)
 * [17 years, 1 month ago](https://wordpress.org/support/topic/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]*)\>/”; $replace=””; 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,
 * Mitul

Viewing 1 replies (of 1 total)

 *  [nmac](https://wordpress.org/support/users/nmac/)
 * (@nmac)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/modifying-wp_head/#post-1053461)
 * 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.
 * Nmac.

Viewing 1 replies (of 1 total)

The topic ‘Modifying wp_head’ is closed to new replies.

## Tags

 * [functions](https://wordpress.org/support/topic-tag/functions/)
 * [head](https://wordpress.org/support/topic-tag/head/)
 * [preg_replace](https://wordpress.org/support/topic-tag/preg_replace/)
 * [wp_head](https://wordpress.org/support/topic-tag/wp_head/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [nmac](https://wordpress.org/support/users/nmac/)
 * Last activity: [16 years, 8 months ago](https://wordpress.org/support/topic/modifying-wp_head/#post-1053461)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
