Title: wp_strip_all_tags
Published: April 25, 2014
Last modified: August 20, 2026

---

# wp_strip_all_tags( string $text, bool $remove_breaks = false ): string

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/wp_strip_all_tags/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/wp_strip_all_tags/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wp_strip_all_tags/?output_format=md#return)
 * [More Information](https://developer.wordpress.org/reference/functions/wp_strip_all_tags/?output_format=md#more-information)
 * [Source](https://developer.wordpress.org/reference/functions/wp_strip_all_tags/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wp_strip_all_tags/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_strip_all_tags/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_strip_all_tags/?output_format=md#user-contributed-notes)

Properly strips all HTML tags including ‘script’ and ‘style’.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/wp_strip_all_tags/?output_format=md#description)󠁿

This differs from strip_tags() because it removes the contents of the `<script>`
and `<style>` tags. E.g. `strip_tags( '<script>something</script>' )` will return‘
something’. [wp_strip_all_tags()](https://developer.wordpress.org/reference/functions/wp_strip_all_tags/)
will return an empty string.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_strip_all_tags/?output_format=md#parameters)󠁿

 `$text`stringrequired

String containing HTML tags

`$remove_breaks`booloptional

Whether to remove left over line breaks and white space chars

Default:`false`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_strip_all_tags/?output_format=md#return)󠁿

 string The processed string.

## 󠀁[More Information](https://developer.wordpress.org/reference/functions/wp_strip_all_tags/?output_format=md#more-information)󠁿

[wp_strip_all_tags()](https://developer.wordpress.org/reference/functions/wp_strip_all_tags/)
is added to the following filters by default (see `[wp-includes/default-filters.php](https://core.trac.wordpress.org/browser/tags/5.3/src/wp-includes/default-filters.php#L0)`):

 * pre_comment_author_url
 * pre_user_url
 * pre_link_url
 * pre_link_image
 * pre_link_rss
 * pre_post_guid

It is also applied to these filters by default when on the administration side of
the site:

 * user_url
 * link_url
 * link_image
 * link_rss
 * comment_url
 * post_guid

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_strip_all_tags/?output_format=md#source)󠁿

    ```php
    function wp_strip_all_tags( $text, $remove_breaks = false ) {
    	if ( is_null( $text ) ) {
    		return '';
    	}

    	if ( ! is_scalar( $text ) ) {
    		/*
    		 * To maintain consistency with pre-PHP 8 error levels,
    		 * wp_trigger_error() is used to trigger an E_USER_WARNING,
    		 * rather than _doing_it_wrong(), which triggers an E_USER_NOTICE.
    		 */
    		wp_trigger_error(
    			'',
    			sprintf(
    				/* translators: 1: The function name, 2: The argument number, 3: The argument name, 4: The expected type, 5: The provided type. */
    				__( 'Warning: %1$s expects parameter %2$s (%3$s) to be a %4$s, %5$s given.' ),
    				__FUNCTION__,
    				'#1',
    				'$text',
    				'string',
    				gettype( $text )
    			),
    			E_USER_WARNING
    		);

    		return '';
    	}

    	$text = preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $text );
    	$text = strip_tags( $text );

    	if ( $remove_breaks ) {
    		$text = preg_replace( '/[\r\n\t ]+/', ' ', $text );
    	}

    	return trim( $text );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/formatting.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/formatting.php#L5600)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/formatting.php#L5600-L5636)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_strip_all_tags/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_trigger_error()](https://developer.wordpress.org/reference/functions/wp_trigger_error/)`wp-includes/functions.php` |

Generates a user-level error/warning/notice/deprecation message.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  |

| Used by | Description | 
| [wp_get_tooltip_helper()](https://developer.wordpress.org/reference/functions/wp_get_tooltip_helper/)`wp-includes/general-template.php` |

Retrieves the markup for an accessible tooltip or toggletip.

  | 
| [wp_send_note_notification()](https://developer.wordpress.org/reference/functions/wp_send_note_notification/)`wp-includes/comment.php` |

Sends a single note mention notification email.

  | 
| [WP_MS_Sites_List_Table::get_primary_column_aria_label()](https://developer.wordpress.org/reference/classes/wp_ms_sites_list_table/get_primary_column_aria_label/)`wp-admin/includes/class-wp-ms-sites-list-table.php` |

Returns a clean label for the primary (URL) column’s row header `aria-label`.

  | 
| [WP_Media_List_Table::get_primary_column_aria_label()](https://developer.wordpress.org/reference/classes/wp_media_list_table/get_primary_column_aria_label/)`wp-admin/includes/class-wp-media-list-table.php` |

Returns a clean label for the primary (File) column’s row header `aria-label`.

  | 
| [WP_Links_List_Table::get_primary_column_aria_label()](https://developer.wordpress.org/reference/classes/wp_links_list_table/get_primary_column_aria_label/)`wp-admin/includes/class-wp-links-list-table.php` |

Returns a clean label for the primary (Name) column’s row header `aria-label`.

  | 
| [WP_Font_Face::generate_and_print()](https://developer.wordpress.org/reference/classes/wp_font_face/generate_and_print/)`wp-includes/fonts/class-wp-font-face.php` |

Generates and prints the `@font-face` styles for the given fonts.

  | 
| [WP_Style_Engine_CSS_Declarations::filter_declaration()](https://developer.wordpress.org/reference/classes/wp_style_engine_css_declarations/filter_declaration/)`wp-includes/style-engine/class-wp-style-engine-css-declarations.php` |

Filters a CSS property + value pair.

  | 
| [WP_REST_URL_Details_Controller::prepare_metadata_for_output()](https://developer.wordpress.org/reference/classes/wp_rest_url_details_controller/prepare_metadata_for_output/)`wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php` |

Prepares the metadata by: – stripping all HTML tags and tag entities.

  | 
| [WP_Application_Passwords_List_Table::print_js_template_row()](https://developer.wordpress.org/reference/classes/wp_application_passwords_list_table/print_js_template_row/)`wp-admin/includes/class-wp-application-passwords-list-table.php` |

Prints the JavaScript template for the new row item.

  | 
| [WP_REST_Block_Directory_Controller::prepare_item_for_response()](https://developer.wordpress.org/reference/classes/wp_rest_block_directory_controller/prepare_item_for_response/)`wp-includes/rest-api/endpoints/class-wp-rest-block-directory-controller.php` |

Parse block metadata for a block, and prepare it for an API response.

  | 
| [wp_check_comment_disallowed_list()](https://developer.wordpress.org/reference/functions/wp_check_comment_disallowed_list/)`wp-includes/comment.php` |

Checks if a comment contains disallowed characters or words.

  | 
| [Plugin_Installer_Skin::do_overwrite()](https://developer.wordpress.org/reference/classes/plugin_installer_skin/do_overwrite/)`wp-admin/includes/class-plugin-installer-skin.php` |

Checks if the plugin can be overwritten and outputs the HTML for overwriting a plugin on upload.

  | 
| [Theme_Installer_Skin::do_overwrite()](https://developer.wordpress.org/reference/classes/theme_installer_skin/do_overwrite/)`wp-admin/includes/class-theme-installer-skin.php` |

Checks if the theme can be overwritten and outputs the HTML for overwriting a theme on upload.

  | 
| [WP_Recovery_Mode_Email_Service::send_recovery_mode_email()](https://developer.wordpress.org/reference/classes/wp_recovery_mode_email_service/send_recovery_mode_email/)`wp-includes/class-wp-recovery-mode-email-service.php` |

Sends the Recovery Mode email to the site admin email address.

  | 
| [_sanitize_text_fields()](https://developer.wordpress.org/reference/functions/_sanitize_text_fields/)`wp-includes/formatting.php` |

Internal helper function to sanitize a string from user input or from the database.

  | 
| [WP_Screen::render_list_table_columns_preferences()](https://developer.wordpress.org/reference/classes/wp_screen/render_list_table_columns_preferences/)`wp-admin/includes/class-wp-screen.php` |

Renders the list table columns preferences.

  | 
| [WP_Posts_List_Table::column_title()](https://developer.wordpress.org/reference/classes/wp_posts_list_table/column_title/)`wp-admin/includes/class-wp-posts-list-table.php` |

Handles the title column output.

  | 
| [WP_List_Table::single_row_columns()](https://developer.wordpress.org/reference/classes/wp_list_table/single_row_columns/)`wp-admin/includes/class-wp-list-table.php` |

Generates the columns for a single row of the table.

  | 
| [do_meta_boxes()](https://developer.wordpress.org/reference/functions/do_meta_boxes/)`wp-admin/includes/template.php` |

Meta-Box template function.

  | 
| [WP_Users_List_Table::single_row()](https://developer.wordpress.org/reference/classes/wp_users_list_table/single_row/)`wp-admin/includes/class-wp-users-list-table.php` |

Generates HTML for a single row on the users.php admin panel.

  | 
| [media_upload_form_handler()](https://developer.wordpress.org/reference/functions/media_upload_form_handler/)`wp-admin/includes/media.php` |

Handles form submissions for the legacy media uploader.

  | 
| [edit_post()](https://developer.wordpress.org/reference/functions/edit_post/)`wp-admin/includes/post.php` |

Updates an existing post with values provided in `$_POST`.

  | 
| [wp_ajax_save_attachment()](https://developer.wordpress.org/reference/functions/wp_ajax_save_attachment/)`wp-admin/includes/ajax-actions.php` |

Handles updating attachment attributes via AJAX.

  | 
| [wp_html_excerpt()](https://developer.wordpress.org/reference/functions/wp_html_excerpt/)`wp-includes/formatting.php` |

Safely extracts not more than the first $count characters from HTML string.

  | 
| [wp_trim_words()](https://developer.wordpress.org/reference/functions/wp_trim_words/)`wp-includes/formatting.php` |

Trims text to a certain number of words.

  | 
| [sanitize_user()](https://developer.wordpress.org/reference/functions/sanitize_user/)`wp-includes/formatting.php` |

Sanitizes a username, stripping out unsafe characters.

  | 
| [WP_Widget_RSS::widget()](https://developer.wordpress.org/reference/classes/wp_widget_rss/widget/)`wp-includes/widgets/class-wp-widget-rss.php` |

Outputs the content for the current RSS widget instance.

  | 
| [wp_admin_bar_my_account_item()](https://developer.wordpress.org/reference/functions/wp_admin_bar_my_account_item/)`wp-includes/admin-bar.php` |

Adds the “My Account” item.

  | 
| [wp_setup_nav_menu_item()](https://developer.wordpress.org/reference/functions/wp_setup_nav_menu_item/)`wp-includes/nav-menu.php` |

Decorates a menu item object with the shared navigation menu item properties.

  |

[Show 24 more](https://developer.wordpress.org/reference/functions/wp_strip_all_tags/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_strip_all_tags/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_strip_all_tags/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.9.0](https://developer.wordpress.org/reference/since/2.9.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_strip_all_tags/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 3 content](https://developer.wordpress.org/reference/functions/wp_strip_all_tags/?output_format=md#comment-content-734)
 2.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/wp_strip_all_tags/#comment-734)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_strip_all_tags%2F%23comment-734)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_strip_all_tags%2F%23comment-734)
 4.  **Example**
 5.      ```php
         $html = '<strong>I am not strong</strong>';
         var_dump($html);
         //output '<strong>I am not strong</strong>'
     
         var_dump(wp_strip_all_tags($html));
         //output 'I am not strong'
         ```
     
 6.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_strip_all_tags%2F%3Freplytocom%3D734%23feedback-editor-734)
 7.   [Skip to note 4 content](https://developer.wordpress.org/reference/functions/wp_strip_all_tags/?output_format=md#comment-content-7010)
 8.    [Giuseppe](https://profiles.wordpress.org/mociofiletto/)  [  2 years ago  ](https://developer.wordpress.org/reference/functions/wp_strip_all_tags/#comment-7010)
 9.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_strip_all_tags%2F%23comment-7010)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_strip_all_tags%2F%23comment-7010)
 10. Be aware that `wp_strip_all_tags()` cannot be used to check if a text is html 
     by a simple comparison between the original string and the parsed string.
      **The
     difference is in the `trim()` applied to the returned value.**
 11.     ```php
         function wrong_is_html( $my_string ) {
             return wp_strip_all_tags( $my_string ) !== $my_string ? true : false;
         }
     
         function is_html( $my_string ) {
             return wp_strip_all_tags( $my_string ) !== trim ( $my_string ) ? true : false;
         }
     
         $a_string = 'this is a simple text string with no html tag, but with an end of line' . PHP_EOL;
         if ( true === wrong_is_html( $a_string ) ) {
             echo 'Is HTML';
         } else {
             echo 'Is not HTML';
         }
     
         if ( true === is_html( $a_string ) ) {
             echo 'Is HTML';
         } else {
             echo 'Is not HTML';
         }
     
         // outputs 
         // Is HTML
         // Is not HTML
         ```
     
 12.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_strip_all_tags%2F%3Freplytocom%3D7010%23feedback-editor-7010)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_strip_all_tags%2F)
before being able to contribute a note or feedback.