twentyseventeen_get_svg( array $args = array() ): string
- Source
wp-content/themes/twentyseventeen/inc/icon-functions.php:36
Compatibility
- WordPress
- core
- 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
$argsarrayoptional- Parameters needed to display an SVG.Default:
array()$iconstringRequired SVG icon filename.$titlestringOptional SVG title.$descstringOptional SVG description.
Return value
string- SVG markup.
Performance profile
How much work a call to twentyseventeen_get_svg() 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
- Trivial
- Scaling
- Constant
- Instructions
- 8–91
- Plugin surface
- None
- Called by
- 5
Touches nothing outside its own arguments.
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 101.
Nothing here hands control to plugin code.
5 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()one call below twentyseventeen_get_svg()
Further down the call graph this can also reach option, 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 · 13 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost twentyseventeen_get_svg() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 8–11 | __() |
!empty($args) && !$args | 47 | wp_parse_args(), esc_attr(), esc_html(), esc_html() |
!empty($args) | 55 | wp_parse_args(), esc_attr(), esc_html(), esc_html(), esc_attr() |
!empty($args) | 56–61 | wp_parse_args(), twentyseventeen_unique_id(), esc_attr(), esc_html(), esc_html() |
!empty($args) | 59 | wp_parse_args(), esc_attr(), esc_html(), esc_html(), esc_html() |
!empty($args) | 64–69 | wp_parse_args(), twentyseventeen_unique_id(), esc_attr(), esc_html(), esc_html(), esc_attr() |
!empty($args) | 67 | wp_parse_args(), esc_attr(), esc_html(), esc_html(), esc_html(), esc_attr() |
!empty($args) | 68–73 | wp_parse_args(), twentyseventeen_unique_id(), esc_attr(), esc_html(), esc_html(), esc_html() |
!empty($args) | 69 | wp_parse_args(), esc_attr(), esc_html(), esc_html(), esc_html(), esc_html() |
!empty($args) | 76–81 | wp_parse_args(), twentyseventeen_unique_id(), esc_attr(), esc_html(), esc_html(), esc_html(), esc_attr() |
!empty($args) | 77 | wp_parse_args(), esc_attr(), esc_html(), esc_html(), esc_html(), esc_html(), esc_attr() |
!empty($args) | 78–83 | wp_parse_args(), twentyseventeen_unique_id(), esc_attr(), esc_html(), esc_html(), esc_html(), esc_html() |
1 further outcome, up to 91 instructions
!empty($args) && $args | 86–91 | wp_parse_args(), twentyseventeen_unique_id(), esc_attr(), esc_html(), esc_html(), esc_html(), esc_html(), esc_attr() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 101 instructions, 8–91 executed per call, 7 branches. The work does not change between versions.
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.
Uses · 5
- __()Retrieves the translation of $text.
- wp_parse_args()Merges user defined arguments into defaults array.
- twentyseventeen_unique_id()Gets unique ID.
- esc_attr()Escaping for HTML attributes.
- esc_html()Escaping for HTML blocks.
Used by · 5
- twentyseventeen_dropdown_icon_to_menu_link()Adds dropdown icon if menu item has children.
- twentyseventeen_entry_footer()Prints HTML with meta information for the categories, tags and comments.
- twentyseventeen_nav_menu_social_icons()Displays SVG icons in social links menu.
- twentyseventeen_scripts()Enqueues scripts and styles.
- twentyseventeen_video_controls()Customizes video play/pause button in the custom header.
Source code
function twentyseventeen_get_svg( $args = array() ) { // Make sure $args are an array. if ( empty( $args ) ) { return __( 'Please define default parameters in the form of an array.', 'twentyseventeen' ); } // Define an icon. if ( false === array_key_exists( 'icon', $args ) ) { return __( 'Please define an SVG icon filename.', 'twentyseventeen' ); } // Set defaults. $defaults = array( 'icon' => '', 'title' => '', 'desc' => '', 'fallback' => false, ); // Parse args. $args = wp_parse_args( $args, $defaults ); // Set aria hidden. $aria_hidden = ' aria-hidden="true"'; // Set ARIA. $aria_labelledby = ''; /* * Twenty Seventeen doesn't use the SVG title or description attributes; non-decorative icons are described with .screen-reader-text. * * However, child themes can use the title and description to add information to non-decorative SVG icons to improve accessibility. * * Example 1 with title: <?php echo twentyseventeen_get_svg( array( 'icon' => 'arrow-right', 'title' => __( 'This is the title', 'textdomain' ) ) ); ?> * * Example 2 with title and description: <?php echo twentyseventeen_get_svg( array( 'icon' => 'arrow-right', 'title' => __( 'This is the title', 'textdomain' ), 'desc' => __( 'This is the description', 'textdomain' ) ) ); ?> * * See https://www.paciellogroup.com/blog/2013/12/using-aria-enhance-svg-accessibility/. */ if ( $args['title'] ) { $aria_hidden = ''; $unique_id = twentyseventeen_unique_id(); $aria_labelledby = ' aria-labelledby="title-' . $unique_id . '"'; if ( $args['desc'] ) { $aria_labelledby = ' aria-labelledby="title-' . $unique_id . ' desc-' . $unique_id . '"'; } } // Begin SVG markup. $svg = '<svg class="icon icon-' . esc_attr( $args['icon'] ) . '"' . $aria_hidden . $aria_labelledby . ' role="img">'; // Display the title. if ( $args['title'] ) { $svg .= '<title id="title-' . $unique_id . '">' . esc_html( $args['title'] ) . '</title>'; // Display the desc only if the title is already set. if ( $args['desc'] ) { $svg .= '<desc id="desc-' . $unique_id . '">' . esc_html( $args['desc'] ) . '</desc>'; } } /* * Display the icon. * * The whitespace around `<use>` is intentional - it is a work around to a keyboard navigation bug in Safari 10. * * See https://core.trac.wordpress.org/ticket/38387. */ $svg .= ' <use href="#icon-' . esc_html( $args['icon'] ) . '" xlink:href="#icon-' . esc_html( $args['icon'] ) . '"></use> '; // Add some markup to use as a fallback for browsers that do not support SVGs. if ( $args['fallback'] ) { $svg .= '<span class="svg-fallback icon-' . esc_attr( $args['icon'] ) . '"></span>'; } $svg .= '</svg>'; return $svg;}Changelog
Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-content/themes/twentyseventeen/inc/icon-functions.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.