jetpack_social_menu_get_svg

Return SVG markup.

Description

(string) jetpack_social_menu_get_svg( (array) $args = array() ); 

Returns (string)

SVG markup.

Parameters (1)

0. $args — Optional. (array) => array()
Parameters needed to display an SVG.

Options

    ;        


    Usage

    1. if ( !function_exists( 'jetpack_social_menu_get_svg' ) ) { 
    2. require_once '/modules/theme-tools/social-menu/icon-functions.php'; 
    3.  
    4. // Parameters needed to display an SVG. 
    5. $args = array(); 
    6.  
    7. // NOTICE! Understand what this does before running. 
    8. $result = jetpack_social_menu_get_svg($args); 
    9.  

    Defined (1)

    The function is defined in the following location(s).

    /modules/theme-tools/social-menu/icon-functions.php  
    1. function jetpack_social_menu_get_svg( $args = array() ) { 
    2. // Make sure $args are an array. 
    3. if ( empty( $args ) ) { 
    4. return esc_html__( 'Please define default parameters in the form of an array.', 'jetpack' ); 
    5.  
    6. // Define an icon. 
    7. if ( false === array_key_exists( 'icon', $args ) ) { 
    8. return esc_html__( 'Please define an SVG icon filename.', 'jetpack' ); 
    9.  
    10. // Set defaults. 
    11. $defaults = array( 
    12. 'icon' => '',  
    13. 'fallback' => false,  
    14. ); 
    15.  
    16. // Parse args. 
    17. $args = wp_parse_args( $args, $defaults ); 
    18.  
    19. // Set aria hidden. 
    20. $aria_hidden = ' aria-hidden="true"'; 
    21.  
    22. // Begin SVG markup. 
    23. $svg = '<svg class="icon icon-' . esc_attr( $args['icon'] ) . '"' . $aria_hidden . ' role="img">'; 
    24.  
    25. /** 
    26. * Display the icon. 
    27. * The whitespace around `<use>` is intentional - it is a work around to a keyboard navigation bug in Safari 10. 
    28. * See https://core.trac.wordpress.org/ticket/38387. 
    29. */ 
    30. $svg .= ' <use href="#icon-' . esc_html( $args['icon'] ) . '" xlink:href="#icon-' . esc_html( $args['icon'] ) . '"></use> '; 
    31.  
    32. // Add some markup to use as a fallback for browsers that do not support SVGs. 
    33. if ( $args['fallback'] ) { 
    34. $svg .= '<span class="svg-fallback icon-' . esc_attr( $args['icon'] ) . '"></span>'; 
    35.  
    36. $svg .= '</svg>'; 
    37.  
    38. return $svg;