jetpack_spotify_shortcode

Parse shortcode arguments and render its output.

Description

(string) jetpack_spotify_shortcode( (array) $atts = array(), (string) $content = '' ); 

Returns (string)

Parameters (2)

0. $atts — Optional. (array) => array()
The atts.
1. $content — Optional. (string) => ''
The content.

Usage

  1. if ( !function_exists( 'jetpack_spotify_shortcode' ) ) { 
  2. require_once '/modules/shortcodes/spotify.php'; 
  3.  
  4. // The atts. 
  5. $atts = array(); 
  6.  
  7. // The content. 
  8. $content = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = jetpack_spotify_shortcode($atts, $content); 
  12.  

Defined (1)

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

/modules/shortcodes/spotify.php  
  1. function jetpack_spotify_shortcode( $atts = array(), $content = '' ) { 
  2.  
  3. if ( ! empty( $content ) ) { 
  4. $id = $content; 
  5. } elseif ( ! empty( $atts['id'] ) ) { 
  6. $id = $atts['id']; 
  7. } elseif ( ! empty( $atts[0] ) ) { 
  8. $id = $atts[0]; 
  9. } else { 
  10. return '<!-- Missing Spotify ID -->'; 
  11.  
  12. if ( empty( $atts['width'] ) ) { 
  13. $atts['width'] = 300; 
  14.  
  15. if ( empty( $atts['height'] ) ) { 
  16. $atts['height'] = 380; 
  17.  
  18. $atts['width'] = (int) $atts['width']; 
  19. $atts['height'] = (int) $atts['height']; 
  20.  
  21. // Spotify accepts both URLs and their Spotify ID format, so let them sort it out and validate 
  22. $embed_url = add_query_arg( 'uri', urlencode( $id ), 'https://embed.spotify.com/' ); 
  23.  
  24. return '<iframe src="' . esc_url( $embed_url ) . '" style="display:block; margin:0 auto; width:' . esc_attr( $atts['width'] ) . 'px; height:' . esc_attr( $atts['height'] ) . 'px;" frameborder="0" allowtransparency="true"></iframe>';