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

---

# wp_slash( string|array $value ): string|array

## In this article

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

[ Back to top](https://developer.wordpress.org/reference/functions/wp_slash/?output_format=md#wp--skip-link--target)

Adds slashes to a string or recursively adds slashes to strings within an array.

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

This should be used when preparing data for core API that expects slashed data.

This should not be used to escape data going directly into an SQL query.

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

 `$value`string|arrayrequired

String or array of data to slash.

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

 string|array Slashed `$value`, in the same type as supplied.

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

    ```php
    function wp_slash( $value ) {
    	if ( is_array( $value ) ) {
    		return array_map( 'wp_slash', $value );
    	}

    	if ( is_string( $value ) ) {
    		return addslashes( $value );
    	}

    	return $value;
    }
    ```

[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#L5864)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/formatting.php#L5864-L5874)

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

| Used by | Description | 
| [WP_REST_Attachments_Controller::sideload_item()](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/sideload_item/)`wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php` |

Side-loads a media file without creating a new attachment.

  | 
| [WP_REST_Attachments_Controller::finalize_item()](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/finalize_item/)`wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php` |

Finalizes an attachment after client-side media processing.

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

Reduces `span` classes in comment content to the note mention tokens.

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

Copy parent attachment properties to newly cropped image.

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

Strips all HTML from the content of footnotes, and sanitizes the ID.

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

Copy post meta for the given key from one post to another.

  | 
| [WP_REST_Menu_Items_Controller::create_item()](https://developer.wordpress.org/reference/classes/wp_rest_menu_items_controller/create_item/)`wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php` |

Creates a single nav menu item.

  | 
| [WP_REST_Menu_Items_Controller::update_item()](https://developer.wordpress.org/reference/classes/wp_rest_menu_items_controller/update_item/)`wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php` |

Updates a single nav menu item.

  | 
| [WP_REST_Menus_Controller::create_item()](https://developer.wordpress.org/reference/classes/wp_rest_menus_controller/create_item/)`wp-includes/rest-api/endpoints/class-wp-rest-menus-controller.php` |

Creates a single term in a taxonomy.

  | 
| [WP_REST_Menus_Controller::update_item()](https://developer.wordpress.org/reference/classes/wp_rest_menus_controller/update_item/)`wp-includes/rest-api/endpoints/class-wp-rest-menus-controller.php` |

Updates a single term from a taxonomy.

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

Sanitizes global styles user content removing unsafe rules.

  | 
| [WP_REST_Widgets_Controller::save_widget()](https://developer.wordpress.org/reference/classes/wp_rest_widgets_controller/save_widget/)`wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php` |

Saves the widget in the request object.

  | 
| [WP_REST_Templates_Controller::update_item()](https://developer.wordpress.org/reference/classes/wp_rest_templates_controller/update_item/)`wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php` |

Updates a single template.

  | 
| [WP_REST_Templates_Controller::create_item()](https://developer.wordpress.org/reference/classes/wp_rest_templates_controller/create_item/)`wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php` |

Creates a single template.

  | 
| [WP_REST_Application_Passwords_Controller::create_item()](https://developer.wordpress.org/reference/classes/wp_rest_application_passwords_controller/create_item/)`wp-includes/rest-api/endpoints/class-wp-rest-application-passwords-controller.php` |

Creates an application password.

  | 
| [WP_REST_Application_Passwords_Controller::update_item()](https://developer.wordpress.org/reference/classes/wp_rest_application_passwords_controller/update_item/)`wp-includes/rest-api/endpoints/class-wp-rest-application-passwords-controller.php` |

Updates an application password.

  | 
| [WP_REST_Attachments_Controller::edit_media_item()](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/edit_media_item/)`wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php` |

Applies edits to a media item and creates a new attachment record.

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

Adds `rel="nofollow ugc"` string to all HTML A elements in content.

  | 
| [WP_REST_Attachments_Controller::insert_attachment()](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/insert_attachment/)`wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php` |

Inserts the attachment post in the database. Does not update the attachment meta.

  | 
| [WP_REST_Autosaves_Controller::create_item()](https://developer.wordpress.org/reference/classes/wp_rest_autosaves_controller/create_item/)`wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php` |

Creates, updates or deletes an autosave revision.

  | 
| [WP_REST_Autosaves_Controller::create_post_autosave()](https://developer.wordpress.org/reference/classes/wp_rest_autosaves_controller/create_post_autosave/)`wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php` |

Creates autosave for the specified post.

  | 
| [WP_Customize_Manager::save_changeset_post()](https://developer.wordpress.org/reference/classes/wp_customize_manager/save_changeset_post/)`wp-includes/class-wp-customize-manager.php` |

Saves the post for the loaded changeset.

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

Updates the `custom_css` post for a given theme.

  | 
| [WP_REST_Meta_Fields::delete_meta_value()](https://developer.wordpress.org/reference/classes/wp_rest_meta_fields/delete_meta_value/)`wp-includes/rest-api/fields/class-wp-rest-meta-fields.php` |

Deletes a meta value for an object.

  | 
| [WP_REST_Meta_Fields::update_multi_meta_value()](https://developer.wordpress.org/reference/classes/wp_rest_meta_fields/update_multi_meta_value/)`wp-includes/rest-api/fields/class-wp-rest-meta-fields.php` |

Updates multiple meta values for an object.

  | 
| [WP_REST_Meta_Fields::update_meta_value()](https://developer.wordpress.org/reference/classes/wp_rest_meta_fields/update_meta_value/)`wp-includes/rest-api/fields/class-wp-rest-meta-fields.php` |

Updates a meta value for an object.

  | 
| [WP_REST_Users_Controller::create_item()](https://developer.wordpress.org/reference/classes/wp_rest_users_controller/create_item/)`wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php` |

Creates a single user.

  | 
| [WP_REST_Users_Controller::update_item()](https://developer.wordpress.org/reference/classes/wp_rest_users_controller/update_item/)`wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php` |

Updates a single user.

  | 
| [WP_REST_Terms_Controller::create_item()](https://developer.wordpress.org/reference/classes/wp_rest_terms_controller/create_item/)`wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php` |

Creates a single term in a taxonomy.

  | 
| [WP_REST_Terms_Controller::update_item()](https://developer.wordpress.org/reference/classes/wp_rest_terms_controller/update_item/)`wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php` |

Updates a single term from a taxonomy.

  | 
| [WP_REST_Posts_Controller::create_item()](https://developer.wordpress.org/reference/classes/wp_rest_posts_controller/create_item/)`wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php` |

Creates a single post.

  | 
| [WP_REST_Posts_Controller::update_item()](https://developer.wordpress.org/reference/classes/wp_rest_posts_controller/update_item/)`wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php` |

Updates a single post.

  | 
| [WP_REST_Comments_Controller::update_item()](https://developer.wordpress.org/reference/classes/wp_rest_comments_controller/update_item/)`wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php` |

Updates a comment.

  | 
| [WP_REST_Comments_Controller::create_item()](https://developer.wordpress.org/reference/classes/wp_rest_comments_controller/create_item/)`wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php` |

Creates a comment.

  | 
| [WP_Customize_Nav_Menus::save_nav_menus_created_posts()](https://developer.wordpress.org/reference/classes/wp_customize_nav_menus/save_nav_menus_created_posts/)`wp-includes/class-wp-customize-nav-menus.php` |

Publishes the auto-draft posts that were created for nav menu items.

  | 
| [WP_Customize_Nav_Menus::insert_auto_draft_post()](https://developer.wordpress.org/reference/classes/wp_customize_nav_menus/insert_auto_draft_post/)`wp-includes/class-wp-customize-nav-menus.php` |

Adds a new `auto-draft` post.

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

Handles the submission of a comment, usually posted to wp-comments-post.php via a comment form.

  | 
| [WP_Customize_Nav_Menu_Setting::update()](https://developer.wordpress.org/reference/classes/wp_customize_nav_menu_setting/update/)`wp-includes/customize/class-wp-customize-nav-menu-setting.php` |

Create/update the nav_menu term for this setting.

  | 
| [WP_Customize_Nav_Menu_Item_Setting::sanitize()](https://developer.wordpress.org/reference/classes/wp_customize_nav_menu_item_setting/sanitize/)`wp-includes/customize/class-wp-customize-nav-menu-item-setting.php` |

Sanitize an input.

  | 
| [WP_Customize_Nav_Menu_Item_Setting::update()](https://developer.wordpress.org/reference/classes/wp_customize_nav_menu_item_setting/update/)`wp-includes/customize/class-wp-customize-nav-menu-item-setting.php` |

Creates/updates the nav_menu_item post for this setting.

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

Aliases [wp_insert_category()](https://developer.wordpress.org/reference/functions/wp_insert_category/) with minimal args.

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

Edit user settings based on contents of $_POST

  | 
| [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.

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

Saves a post submitted with XHR.

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

Adds post meta data defined in the `$_POST` superglobal for a post with given ID.

  | 
| [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_ajax_inline_save()](https://developer.wordpress.org/reference/functions/wp_ajax_inline_save/)`wp-admin/includes/ajax-actions.php` |

Handles Quick Edit saving a post from a list table via AJAX.

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

Handles replying to a comment via AJAX.

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

Updates a link in the database.

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

Adds slashes to a string or recursively adds slashes to strings within an array.

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

Adds `rel="nofollow"` string to all HTML A elements in content.

  | 
| [WP_Query::get_posts()](https://developer.wordpress.org/reference/classes/wp_query/get_posts/)`wp-includes/class-wp-query.php` |

Retrieves an array of posts based on query variables.

  | 
| [WP_Embed::shortcode()](https://developer.wordpress.org/reference/classes/wp_embed/shortcode/)`wp-includes/class-wp-embed.php` |

The [do_shortcode()](https://developer.wordpress.org/reference/functions/do_shortcode/) callback function.

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

Updates term based on arguments provided.

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

Provides a simpler way of inserting a user into the database.

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

Inserts a user into the database.

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

Updates a post with new post data.

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

Inserts post data into the posts table as a post revision.

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

Restores a post to the specified revision.

  | 
| [wp_xmlrpc_server::escape()](https://developer.wordpress.org/reference/classes/wp_xmlrpc_server/escape/)`wp-includes/class-wp-xmlrpc-server.php` |

Escapes string or array of strings for database.

  | 
| [WP_Customize_Widgets::call_widget_update()](https://developer.wordpress.org/reference/classes/wp_customize_widgets/call_widget_update/)`wp-includes/class-wp-customize-widgets.php` |

Finds and invokes the widget update and control callbacks.

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

Updates an existing comment in the database.

  |

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

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

| Version | Description | 
| [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Non-string values are left untouched. | 
| [3.6.0](https://developer.wordpress.org/reference/since/3.6.0/) | Introduced. |

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

 1.   [Skip to note 3 content](https://developer.wordpress.org/reference/functions/wp_slash/?output_format=md#comment-content-1466)
 2.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/wp_slash/#comment-1466)
 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_slash%2F%23comment-1466)
     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_slash%2F%23comment-1466)
 4.  **Usage with a string**
 5.  How to use wp_slash with a string within your plugin.
 6.      ```php
         function wpdocs_toolset_string_add_slashes() {
             $name = __( "O'Reilly & Associates", 'textdomain' );
             $name = wp_slash( $name );
             echo "name={$name}";
         }
         add_action( 'pre_get_posts', 'wpdocs_toolset_string_add_slashes' );
         ```
     
 7.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_slash%2F%3Freplytocom%3D1466%23feedback-editor-1466)
 8.   [Skip to note 4 content](https://developer.wordpress.org/reference/functions/wp_slash/?output_format=md#comment-content-1467)
 9.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/wp_slash/#comment-1467)
 10. [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_slash%2F%23comment-1467)
     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_slash%2F%23comment-1467)
 11. **Usage with an array**
 12. How to use wp_slash with an array within your plugin.
 13.     ```php
         function wpdocs_toolset_array_add_slashes() {
             $names = array( __( "Baba O'Reilly", 'textdomain' ), __( 'class of '99', 'textdomain' ) );
             $names = wp_slash( $names );
             print_r( $names );
         }
         add_action( 'pre_get_posts', 'wpdocs_toolset_array_add_slashes' );
         ```
     
 14.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_slash%2F%3Freplytocom%3D1467%23feedback-editor-1467)

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