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

---

# wp_specialchars_decode( string $text, string|int $quote_style = ENT_NOQUOTES ): string

## In this article

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

Converts a number of HTML entities into their special characters.

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

Specifically deals with: `&`, `<`, `>`, `"`, and `'`.

`$quote_style` can be set to ENT_COMPAT to decode `"` entities, or ENT_QUOTES to
do both `"` and `'`. Default is ENT_NOQUOTES where no quotes are decoded.

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

 `$text`stringrequired

The text which is to be decoded.

`$quote_style`string|intoptional

Converts double quotes if set to ENT_COMPAT, both single and double if set to ENT_QUOTES
or none if set to ENT_NOQUOTES.
 Also compatible with old [_wp_specialchars()](https://developer.wordpress.org/reference/functions/_wp_specialchars/)
values; converting single quotes if set to `'single'`, double if set to `'double'`
or both if otherwise set. Default is ENT_NOQUOTES.

More Arguments from _wp_specialchars( … $quote_style )

Converts double quotes if set to ENT_COMPAT, both single and double if set to ENT_QUOTES
or none if set to ENT_NOQUOTES.
 Converts single and double quotes, as well as converting
HTML named entities (that are not also XML named entities) to their code points 
if set to ENT_XML1. Also compatible with old values; converting single quotes if
set to `'single'`, double if set to `'double'` or both if otherwise set. Default
is ENT_NOQUOTES.

Default:`ENT_NOQUOTES`

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

 string The decoded text without HTML entities.

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

    ```php
    function wp_specialchars_decode( $text, $quote_style = ENT_NOQUOTES ) {
    	$text = (string) $text;

    	if ( 0 === strlen( $text ) ) {
    		return '';
    	}

    	// Don't bother if there are no entities - saves a lot of processing.
    	if ( ! str_contains( $text, '&' ) ) {
    		return $text;
    	}

    	// Match the previous behavior of _wp_specialchars() when the $quote_style is not an accepted value.
    	if ( empty( $quote_style ) ) {
    		$quote_style = ENT_NOQUOTES;
    	} elseif ( ! in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) {
    		$quote_style = ENT_QUOTES;
    	}

    	// More complete than get_html_translation_table( HTML_SPECIALCHARS ).
    	$single      = array(
    		'&#039;' => '\'',
    		'&#x27;' => '\'',
    	);
    	$single_preg = array(
    		'/&#0*39;/'   => '&#039;',
    		'/&#x0*27;/i' => '&#x27;',
    	);
    	$double      = array(
    		'&quot;' => '"',
    		'&#034;' => '"',
    		'&#x22;' => '"',
    	);
    	$double_preg = array(
    		'/&#0*34;/'   => '&#034;',
    		'/&#x0*22;/i' => '&#x22;',
    	);
    	$others      = array(
    		'&lt;'   => '<',
    		'&#060;' => '<',
    		'&gt;'   => '>',
    		'&#062;' => '>',
    		'&amp;'  => '&',
    		'&#038;' => '&',
    		'&#x26;' => '&',
    	);
    	$others_preg = array(
    		'/&#0*60;/'   => '&#060;',
    		'/&#0*62;/'   => '&#062;',
    		'/&#0*38;/'   => '&#038;',
    		'/&#x0*26;/i' => '&#x26;',
    	);

    	if ( ENT_QUOTES === $quote_style ) {
    		$translation      = array_merge( $single, $double, $others );
    		$translation_preg = array_merge( $single_preg, $double_preg, $others_preg );
    	} elseif ( ENT_COMPAT === $quote_style || 'double' === $quote_style ) {
    		$translation      = array_merge( $double, $others );
    		$translation_preg = array_merge( $double_preg, $others_preg );
    	} elseif ( 'single' === $quote_style ) {
    		$translation      = array_merge( $single, $others );
    		$translation_preg = array_merge( $single_preg, $others_preg );
    	} elseif ( ENT_NOQUOTES === $quote_style ) {
    		$translation      = $others;
    		$translation_preg = $others_preg;
    	}

    	// Remove zero padding on numeric entities.
    	$text = preg_replace( array_keys( $translation_preg ), array_values( $translation_preg ), $text );

    	// Replace characters according to translation table.
    	return strtr( $text, $translation );
    }
    ```

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

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

| Used by | Description | 
| [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.

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

Notifies the Multisite network administrator that a new site was created.

  | 
| [WP_Automatic_Updater::send_plugin_theme_email()](https://developer.wordpress.org/reference/classes/wp_automatic_updater/send_plugin_theme_email/)`wp-admin/includes/class-wp-automatic-updater.php` |

Sends an email upon the completion or failure of a plugin or theme background update.

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

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

Notifies the site administrator via email when a request is confirmed.

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

Notifies the user when their erasure request is fulfilled.

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

Send a confirmation request email to confirm an action.

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

Send an email to the user with a link to the personal data export file

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

Sends an email to the old site admin email address when the site admin email address changes.

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

Sends a confirmation request email when a change of network admin email address is attempted.

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

Sends an email to the old network admin email address when the network admin email address changes.

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

Handles sending a password retrieval email to a user.

  | 
| [WP_Automatic_Updater::send_email()](https://developer.wordpress.org/reference/classes/wp_automatic_updater/send_email/)`wp-admin/includes/class-wp-automatic-updater.php` |

Sends an email upon the completion or failure of a background core update.

  | 
| [WP_Automatic_Updater::send_debug_email()](https://developer.wordpress.org/reference/classes/wp_automatic_updater/send_debug_email/)`wp-admin/includes/class-wp-automatic-updater.php` |

Prepares and sends an email of a full log of background update results, useful for debugging and geekery.

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

Sends a confirmation request email when a change of site admin email address is attempted.

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

Sends a confirmation request email when a change of user email address is attempted.

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

Notifies the blog admin of a user changing password, normally via email.

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

Emails login credentials to a newly-registered user.

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

Notifies an author (and/or others) of a comment/trackback/pingback on a post.

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

Notifies the moderator of the site about a new comment that is awaiting approval.

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

Updates a user in the database.

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

Notifies a user that their account activation has been successful.

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

Notifies the site administrator that their site activation was successful.

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

Sends a confirmation request email to a user when they sign up for a new site. The new site will not become active until the confirmation link is clicked.

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

Sends a confirmation request email to a user when they sign up for a new user account (without signing up for a site at the same time). The user account will not become active until the confirmation link is clicked.

  |

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

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

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

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

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/wp_specialchars_decode/?output_format=md#comment-content-4251)
 2.   [Noptin Newsletter Team](https://profiles.wordpress.org/picocodes/)  [  6 years ago  ](https://developer.wordpress.org/reference/functions/wp_specialchars_decode/#comment-4251)
 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_specialchars_decode%2F%23comment-4251)
    Vote results for this note: 5[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_specialchars_decode%2F%23comment-4251)
 4. Beware that this function does not decode all entities. For example, it does not
    decode `&#8211`.
 5. If you encounter such an issue, try using `html_entity_decode()`.
 6.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_specialchars_decode%2F%3Freplytocom%3D4251%23feedback-editor-4251)

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