get_the_generator( string $type = '' ): string|void
- Since
- 2.5.0
- Source
wp-includes/general-template.php:5138
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
- Scaling
- Constant
- Instructions
- 9–61
- Plugin surface
- 1 hook
- Called by
- 1
Reads stored settings via get_option(), cached per request but not free on a cold cache.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 126.
Third-party callbacks on 'get_the_generator_{$type}' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly - optionoption read or write
get_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.
| When | Instructions | Calls it makes |
|---|---|---|
empty($type) && empty($current_filter) | 9 | current_filter() |
!empty($type) | 11–26 | apply_filters() |
empty($type) && !empty($current_filter) | 17–49 | current_filter(), apply_filters() |
!empty($type) | 20–32 | get_bloginfo(), esc_attr(), apply_filters() |
!empty($type) | 20–26 | get_bloginfo_rss(), esc_attr(), apply_filters() |
!empty($type) | 21–31 | get_bloginfo_rss(), sanitize_url(), apply_filters() |
!empty($type) | 24–38 | get_bloginfo_rss(), esc_attr(), gmdate(), apply_filters() |
empty($type) && !empty($current_filter) | 26–55 | current_filter(), get_bloginfo(), esc_attr(), apply_filters() |
empty($type) && !empty($current_filter) | 26–49 | current_filter(), get_bloginfo_rss(), esc_attr(), apply_filters() |
empty($type) && !empty($current_filter) | 27–54 | current_filter(), get_bloginfo_rss(), sanitize_url(), apply_filters() |
empty($type) && !empty($current_filter) | 30–61 | current_filter(), get_bloginfo_rss(), esc_attr(), gmdate(), apply_filters() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 126 | 9–61 | 19 | |
| 8.5 | 126 | 9–61 | 19 | |
| 8.4 | 126 | 9–61 | 19 | |
| 8.3 | 126 | 9–61 | 19 | |
| 8.2 | 126 | 9–61 | 19 | 2 more instructions than PHP 8.1 |
| 8.1 | 124 | 9–62 | 19 | |
| 7.4 | 124 | 9–62 | 19 |
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:
- apply_filters( get_the_generator_{$type} )filterline 5211 (+73 into the body)
Filters the HTML for the retrieved generator type.
Uses · 6
- current_filter()Retrieves the name of the current filter hook.
- esc_attr()Escaping for HTML attributes.
- get_bloginfo()Retrieves information about the current site.
- get_bloginfo_rss()Retrieves RSS container for the bloginfo function.
- sanitize_url()Sanitizes a URL for database or redirect usage.
- apply_filters()Calls the callback functions that have been added to a filter hook.
Used by · 1
- the_generator()Displays the generator XML or Comment for RSS, ATOM, etc.
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.
Signature, return type and hooks compared across 5 parsed releases.
string|void to string|null.verified against sourceAbout this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 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.