wppaste
WordPress

get_the_generator( string $type = '' ): string|void

Since
2.5.0
Source
wp-includes/general-template.php:5152
Creates the generator XML or Comment for RSS, ATOM, etc.

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_thegenerator$type' filter.

Compatibility

WordPress
since 2.5.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$typestringoptional
The type of generator to return - (html|xhtml|atom|rss2|rdf|comment|export).Default: ''

Return value

string|void
The HTML content for the generator.

Performance profile

How much work a call to get_the_generator() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Moderate

Reads stored settings via get_option(), cached per request but not free on a cold cache.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
9–61

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 126.

Plugin surface
1 hook

Third-party callbacks on 'get_the_generator_{$type}' run inside this call, and their cost is not bounded by anything here.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksapply_filters()called directly
  • optionoption read or writeget_option()one call below get_the_generator()

Further down the call graph this can also reach cache, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 11 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost get_the_generator() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
empty($type) && empty($current_filter)9current_filter()
!empty($type)11–26apply_filters()
empty($type) && !empty($current_filter)17–49current_filter(), apply_filters()
!empty($type)20–32get_bloginfo(), esc_attr(), apply_filters()
!empty($type)20–26get_bloginfo_rss(), esc_attr(), apply_filters()
!empty($type)21–31get_bloginfo_rss(), sanitize_url(), apply_filters()
!empty($type)24–38get_bloginfo_rss(), esc_attr(), gmdate(), apply_filters()
empty($type) && !empty($current_filter)26–55current_filter(), get_bloginfo(), esc_attr(), apply_filters()
empty($type) && !empty($current_filter)26–49current_filter(), get_bloginfo_rss(), esc_attr(), apply_filters()
empty($type) && !empty($current_filter)27–54current_filter(), get_bloginfo_rss(), sanitize_url(), apply_filters()
empty($type) && !empty($current_filter)30–61current_filter(), get_bloginfo_rss(), esc_attr(), gmdate(), apply_filters()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev1269–6119
8.51269–6119
8.41269–6119
8.31269–6119
8.21269–61192 more instructions than PHP 8.1
8.11249–6219
7.41249–6219

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 1

One hook fires while get_the_generator() runs, in this order:

  1. apply_filters( get_the_generator_{$type} )filterline 5225 (+73 into the body)

    Filters the HTML for the retrieved generator type.

Uses · 6

Used by · 1

Source code

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 );}

Changelog

Introduced in 2.5.0. One change between 6.7.7 and 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

7.0.4
Return type changed from string|void to string|null.verified against source
2.5.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.9.7 tag, from src/wp-includes/general-template.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.