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

---

# wxr_cdata( string|null $str ): string

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/wxr_cdata/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wxr_cdata/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wxr_cdata/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wxr_cdata/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wxr_cdata/?output_format=md#changelog)

Wraps given string in XML CDATA tag.

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

 `$str`string|nullrequired

String to wrap in XML CDATA tag. May be null.

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

 string

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

    ```php
    function wxr_cdata( $str ) {
    	$str = (string) $str;

    	if ( ! wp_is_valid_utf8( $str ) ) {
    		$str = utf8_encode( $str );
    	}
    	// $str = ent2ncr(esc_html($str));
    	$str = '<![CDATA[' . str_replace( ']]>', ']]]]><![CDATA[>', $str ) . ']]>';

    	return $str;
    }
    ```

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

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

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

Determines if a given byte string represents a valid UTF-8 encoding.

  |

| Used by | Description | 
| [wxr_term_meta()](https://developer.wordpress.org/reference/functions/wxr_term_meta/)`wp-admin/includes/export.php` |

Outputs term meta XML tags for a given term object.

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

Outputs list of taxonomy terms, in XML tag format, associated with a post.

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

Generates the WXR export file for download.

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

Outputs a cat_name XML tag from a given category object.

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

Outputs a category_description XML tag from a given category object.

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

Outputs a tag_name XML tag from a given tag object.

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

Outputs a tag_description XML tag from a given tag object.

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

Outputs a term_name XML tag from a given term object.

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

Outputs a term_description XML tag from a given term object.

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

Outputs list of authors with posts.

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

Outputs all navigation menu terms.

  |

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

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

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

## User Contributed Notes

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