Title: get_the_generator
Published: April 25, 2014
Last modified: February 24, 2026

---

# get_the_generator( string $type ): string|void

## In this article

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

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

Creates the generator XML or Comment for RSS, ATOM, etc.

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

Returns the correct generator type for the requested output format. Allows for a
plugin to filter generators on an individual basis using the [‘get_the_generator_$type’](https://developer.wordpress.org/reference/hooks/get_the_generator_type/)
filter.

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

 `$type`stringrequired

The type of generator to return – (`html|xhtml|atom|rss2|rdf|comment|export`).

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

 string|void The HTML content for the generator.

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

    ```php
    function get_the_generator( $type = '' ) {
    	if ( empty( $type ) ) {

    		$current_filter = current_filter();
    		if ( empty( $current_filter ) ) {
    			return;
    		}

    		switch ( $current_filter ) {
    			case 'rss2_head':
    			case 'commentsrss2_head':
    				$type = 'rss2';
    				break;
    			case 'rss_head':
    			case 'opml_head':
    				$type = 'comment';
    				break;
    			case 'rdf_header':
    				$type = 'rdf';
    				break;
    			case 'atom_head':
    			case 'comments_atom_head':
    			case 'app_head':
    				$type = 'atom';
    				break;
    		}
    	}

    	switch ( $type ) {
    		case 'html':
    			$gen = '<meta name="generator" content="WordPress ' . esc_attr( get_bloginfo( 'version' ) ) . '">';
    			break;
    		case 'xhtml':
    			$gen = '<meta name="generator" content="WordPress ' . esc_attr( get_bloginfo( 'version' ) ) . '" />';
    			break;
    		case 'atom':
    			$gen = '<generator uri="https://wordpress.org/" version="' . esc_attr( get_bloginfo_rss( 'version' ) ) . '">WordPress</generator>';
    			break;
    		case 'rss2':
    			$gen = '<generator>' . sanitize_url( 'https://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) ) . '</generator>';
    			break;
    		case 'rdf':
    			$gen = '<admin:generatorAgent rdf:resource="' . sanitize_url( 'https://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) ) . '" />';
    			break;
    		case 'comment':
    			$gen = '<!-- generator="WordPress/' . esc_attr( get_bloginfo( 'version' ) ) . '" -->';
    			break;
    		case 'export':
    			$gen = '<!-- generator="WordPress/' . esc_attr( get_bloginfo_rss( 'version' ) ) . '" created="' . gmdate( 'Y-m-d H:i' ) . '" -->';
    			break;
    	}

    	/**
    	 * Filters the HTML for the retrieved generator type.
    	 *
    	 * The dynamic portion of the hook name, `$type`, refers to the generator type.
    	 *
    	 * Possible hook names include:
    	 *
    	 *  - `get_the_generator_atom`
    	 *  - `get_the_generator_comment`
    	 *  - `get_the_generator_export`
    	 *  - `get_the_generator_html`
    	 *  - `get_the_generator_rdf`
    	 *  - `get_the_generator_rss2`
    	 *  - `get_the_generator_xhtml`
    	 *
    	 * @since 2.5.0
    	 *
    	 * @param string $gen  The HTML markup output to wp_head().
    	 * @param string $type The type of generator. Accepts 'html', 'xhtml', 'atom',
    	 *                     'rss2', 'rdf', 'comment', 'export'.
    	 */
    	return apply_filters( "get_the_generator_{$type}", $gen, $type );
    }
    ```

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

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/get_the_generator/?output_format=md#hooks)󠁿

 [apply_filters( “get_the_generator_{$type}”, string $gen, string $type )](https://developer.wordpress.org/reference/hooks/get_the_generator_type/)

Filters the HTML for the retrieved generator type.

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

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

Retrieves the name of the current filter hook.

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

Retrieves RSS container for the bloginfo function.

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

Escaping for HTML attributes.

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

Retrieves information about the current site.

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

Sanitizes a URL for database or redirect usage.

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

Calls the callback functions that have been added to a filter hook.

  |

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

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

Displays the generator XML or Comment for RSS, ATOM, etc.

  |

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

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

## User Contributed Notes

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