Yotuwp Easy Youtube Embed Shortcode

Below, you’ll find a detailed guide on how to add the Yotuwp Easy Youtube Embed Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Yotuwp Easy Youtube Embed Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Yotuwp Easy Youtube Embed Plugin and the shortcodes it provides:

Plugin Icon
Video Gallery – YouTube Playlist, Channel Gallery by YotuWP

"Video Gallery – YouTube Playlist, Channel Gallery by YotuWP is a WordPress plugin that allows easy embedding of YouTube videos. It supports playlists, channels, and gallery displays for user-friendly video management."

★★★★☆ (305) Active Installs: 30000+ Tested with: 6.2.3 PHP Version: false
Included Shortcodes:
  • [yotuwp]

Yotuwp Easy Youtube Embed [yotuwp] Shortcode

The yotuwp shortcode is a powerful tool that allows users to embed YouTube videos on their WordPress site. It enqueues necessary styles and scripts, generates unique gallery ID, and handles custom styling.

Shortcode: [yotuwp]

Parameters

Here is a list of all possible yotuwp shortcode parameters and attributes:

  • styling – This parameter is used to customize the style of the YouTube video player.
  • effects – It’s used to apply specific visual effects to the video player.
  • meta – This parameter controls whether to display video metadata or not.
  • player – It’s used to configure the video player settings.
  • gallery_id – It generates a unique ID for each video gallery.

Examples and Usage

Basic example – An example of using the yotuwp shortcode to embed a YouTube video into your WordPress site.

[yotuwp type="video" id="Ks-_Mh1QhMc" /]

Advanced examples

Embed a YouTube playlist with specific player, styling, and effect settings. The player settings are passed as a string of parameters, the styling settings control the visual appearance, and the effects settings control the animation effects.

[yotuwp type="playlist" id="PL2fnLUTsNyq7A335zB_RpOzu7hEUcSJbB" player="autoplay=1&controls=0&showinfo=0&rel=0" styling="color=blue&size=large" effects="fadein=slow&fadeout=fast" /]

Embed a YouTube channel with custom player settings. The player settings control the behavior of the video player, such as autoplay, controls, showinfo, and related videos.

[yotuwp type="channel" id="UC_x5XG1OV2P6uZZ5FSM9Ttw" player="autoplay=1&controls=0&showinfo=0&rel=0" /]

Embed a YouTube video with custom styling settings. The styling settings control the visual appearance of the video, such as color and size.

[yotuwp type="video" id="Ks-_Mh1QhMc" styling="color=blue&size=large" /]

Embed a YouTube video with custom effect settings. The effect settings control the animation effects of the video, such as fade-in and fade-out.

[yotuwp type="video" id="Ks-_Mh1QhMc" effects="fadein=slow&fadeout=fast" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [yotuwp] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'yotuwp', 						array( $this, 'shortcode' ) );

Shortcode PHP function:

function shortcode( $atts ) {
		global $yotuwp_inline_script;
		wp_enqueue_style( 'yotu-style' );
		wp_enqueue_style( 'yotu-icons' );
		wp_enqueue_style( 'yotupro' );
		wp_enqueue_style( 'yotu-presets' );
		wp_enqueue_style( 'yotupro-effs' );

		wp_enqueue_script( 'yotu-script' );
		wp_enqueue_script( 'yotupro' );

		$default = $this->options;

		$default['styling']   = '';
		$default['effects']   = '';
		$default['meta']   		= isset($default['meta'])? $default['meta'] : 'off';
		$atts 				= shortcode_atts( $default, $atts, 'yotu' );
		$player_options 	= $this->player;
		$styling_options 	= $this->styling;
		$effects_options 	= $this->effects;

		do_action( 'yotuwp_before_shortcode', $atts );

		if ( $atts['player'] !='' ) {
			
			parse_str( $atts['player'], $player );

			if ( is_array( $player) ) {
				foreach ( $player as $key => $value)
					$player_options[ $key] = ( $key !== 'mode' )? intval( $player[ $key] ) : $player[ $key];
			}
		}

		if ( $atts['effects'] !='' ) {
			
			parse_str( $atts['effects'], $effects );

			if ( is_array( $effects) ) {
				foreach ( $effects as $key => $value)
					$effects_options[ $key] = $effects[ $key];
			}
		}

		$atts['gallery_id']   = uniqid();

		if (isset($atts['styling']) && $atts['styling'] !='') {

			$custom_styling = array();			
			parse_str(htmlspecialchars_decode($atts['styling']), $styling);

			if (is_array($styling)) {
				foreach ( $styling as $key => $value){
					$custom_styling[$key] = $styling[$key];
					$styling_options[$key] = $styling[$key];
				}
				
				//render custom css
				$custom_css = '';
				foreach ( $this->views->sections as $tab ) {
					foreach ( $tab['fields'] as $field) {
						
						if (isset($field['css']) && isset($custom_styling[$field['name']])) {
							$data 		= explode( '|', $field['css'] );
							$selector 	= str_replace('body', 'body #yotuwp-'. $atts['gallery_id'], $data[0]);
							$custom_css .= !empty( $custom_styling[ $field['name']] )? $selector.'{'.$data[1].':'.$custom_styling[ $field['name']].(isset($data[2])? '!important': '').'}' : '';
						}
					}
				};
				
				wp_add_inline_style( 'yotu-style', $custom_css );
			}
			
		}
		
		if ( $player_options['thumbnails'] ) {
			wp_enqueue_style( 'jquery-owlcarousel' );
			wp_enqueue_style( 'jquery-owlcarousel-theme' );
			wp_enqueue_script( 'jquery-owlcarousel' );
		}

		$atts['player'] 	= $player_options;
		$atts['styling'] 	= $styling_options;
		$atts['effects'] 	= $effects_options;
		$data 				= $this->prepare( $atts);
		$ids 				= array();
		
		if (
			is_object( $data ) 
			&& count( $data->items) >0
		) {
			foreach( $data->items as $video ) {
				$videoId 	= $this->getVideoId( $video );
				$ids[] 		= $videoId;
				$info 		= array( yotuwp_video_title($video), yotuwp_video_description($video) );
				$yotuwp_inline_script .= "yotuwp.data.videos['" . $videoId . "'] = " . json_encode( $info, true ) . ';';
				
			}
		}
		
		$data = apply_filters( 'yotuwp_data', $data, $ids );
		$html = $this->views->display( $atts['template'], $data, $atts );

		do_action( 'yotuwp_after_shortcode', $atts );

		return $html;
	}

Code file location:

yotuwp-easy-youtube-embed/yotuwp-easy-youtube-embed/yotuwp.php

Conclusion

Now that you’ve learned how to embed the Yotuwp Easy Youtube Embed Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *