Title: wp_rel_ugc
Published: November 12, 2019
Last modified: February 24, 2026

---

# wp_rel_ugc( string $text ): string

## In this article

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

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

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

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

 `$text`stringrequired

Content that may contain HTML A elements.

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

 string Converted content.

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

    ```php
    function wp_rel_ugc( $text ) {
    	// This is a pre-save filter, so text is already escaped.
    	$text = stripslashes( $text );
    	$text = preg_replace_callback(
    		'|<a (.+?)>|i',
    		static function ( $matches ) {
    			return wp_rel_callback( $matches, 'nofollow ugc' );
    		},
    		$text
    	);
    	return wp_slash( $text );
    }
    ```

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

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

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

Callback to add a rel attribute to HTML A element.

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

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

  |

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

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

## User Contributed Notes

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