RSS Feed Widget Shortcode

Below, you’ll find a detailed guide on how to add the RSS Feed Widget 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 RSS Feed Widget Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the RSS Feed Widget Plugin and the shortcodes it provides:

Plugin Icon
RSS Feed Widget

"RSS Feed Widget is a dynamic WordPress plugin that effortlessly integrates and displays RSS feeds within your site, enhancing content diversity and user engagement."

★★★★✩ (24) Active Installs: 4000+ Tested with: 6.2.3 PHP Version: 7.0
Included Shortcodes:
  • [rfw-youtube-videos]

RSS Feed Widget [rfw-youtube-videos] Shortcode

The RSS Feed Widget shortcode ‘rfw-youtube-videos’ displays YouTube videos in a WordPress site. It retrieves video IDs stored in the ‘rfw_sc_ids’ option and embeds them into iframes. The shortcode accepts parameters like ‘number’ (default is 3) to limit the number of videos. ‘Fullscreen’, ‘bgcolor’, ‘width’, ‘height’, and ‘margin’ attributes are for customization.

Shortcode: [rfw-youtube-videos]

Parameters

Here is a list of all possible rfw-youtube-videos shortcode parameters and attributes:

  • number – determines the number of YouTube videos to display
  • fullscreen – if set to true, videos will be displayed in fullscreen mode
  • bgcolor – sets the background color of the video display area
  • width – sets the width of the video display area
  • height – sets the height of the video display area
  • margin – sets the margin around the video display area

Examples and Usage

Basic example – Display three YouTube videos using the ‘rfw-youtube-videos’ shortcode. The number of videos is set by the ‘number’ attribute.

[rfw-youtube-videos number=3 /]

Advanced examples

Display five YouTube videos in fullscreen mode. The ‘number’ attribute sets the number of videos, and the ‘fullscreen’ attribute enables fullscreen mode.

[rfw-youtube-videos number=5 fullscreen=true /]

Show a single YouTube video with a custom background color. The ‘bgcolor’ attribute sets the background color of the video container.

[rfw-youtube-videos number=1 bgcolor="#ff0000" /]

Display four YouTube videos with custom width, height, and margin. The ‘width’, ‘height’, and ‘margin’ attributes allow you to customize the size and positioning of the video container.

[rfw-youtube-videos number=4 width="500px" height="300px" margin="20px" /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'rfw-youtube-videos', 'rfw_youtube_videos' );

Shortcode PHP function:

function rfw_youtube_videos( $atts ) {
		
		$atts['number'] = (isset($atts['number']) && is_numeric($atts['number']) && $atts['number']>0?$atts['number']:3);
		
		global $rfw_footer_scripts, $rfw_youtube_videos_number;
		
		$rfw_youtube_videos_number = $atts['number'];
		
		$common_style = '<style type="text/css">';
		if(isset($atts['fullscreen']) && $atts['fullscreen']=='true'){
			$common_style .= 'body *:not(iframe) {
				width: 100% !important;
				padding: 0 !important;
				margin: 0 !important;
				max-width: 100% !important;
			}';
			$common_style .= 'header, footer, #wpadminbar, .wp_breadcrumb{ display:none !important; } html{ margin:0 !important; }';
		}
		$common_style .= '</style>';
		
		$rfw_footer_scripts['styles'] = $common_style;
		
		$ret = array();
		
		$rfw_sc_ids = get_option('rfw_sc_ids', '');
		$rfw_sc_arr = array();
		if($rfw_sc_ids!=''){
			$rfw_sc_ids = nl2br($rfw_sc_ids);
			//pree($rfw_sc_ids);
			$rfw_sc_arr = explode('<br />', $rfw_sc_ids);
			$rfw_sc_arr = array_filter(array_map('trim', $rfw_sc_arr));
			$rfw_sc_arr = array_map('rfw_clean_yt_links', $rfw_sc_arr);
			//pree($rfw_sc_arr);
			if(!empty($rfw_sc_arr)){
				$item_id_to_remove = array();
				foreach($rfw_sc_arr as $item_id=>$rfw_sc_item){
					$rfw_sc_item_arr = explode(',', $rfw_sc_item);
					if(is_array($rfw_sc_item_arr) && count($rfw_sc_item_arr)>1){				
						//pree($rfw_sc_item_arr);		
						$rfw_sc_arr = array_merge($rfw_sc_arr, $rfw_sc_item_arr);
						$item_id_to_remove[] = $item_id;
						
					}
				}
				if(!empty($item_id_to_remove)){
					foreach($item_id_to_remove as $item_id){
						unset($rfw_sc_arr[$item_id]);
					}
				}
			}
			$rfw_sc_arr = array_filter($rfw_sc_arr, 'strlen');
			//pree($rfw_sc_arr);exit;
			
			$styles = array();
			
			$styles['wrapper'][] = 'style="';
			$styles['wrapper'][] = (isset($atts['bgcolor'])?'background-color:'.$atts['bgcolor'].';':'');
			$styles['wrapper'][] = '"';
						
			$styles['inner'][] = 'style="';
			$styles['inner'][] = (isset($atts['width'])?'width:'.$atts['width'].';':'');
			$styles['inner'][] = (isset($atts['height'])?'height:'.$atts['height'].';':'');
			$styles['inner'][] = (isset($atts['margin'])?'margin:'.$atts['margin'].';':'');
			$styles['inner'][] = '"';
			
			if(!empty($rfw_sc_arr)){
				//pree($rfw_sc_arr);exit;
				$ret[] = '<div class="rfw-yt-items" '.implode('', $styles['wrapper']).'>';
				foreach($rfw_sc_arr as $sc_item){
					$ret[] = '<iframe '.implode('', $styles['inner']).' src="https://www.youtube.com/embed/'.$sc_item.'" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>';
				}
				$ret[] = '</div>';
			}
		}
		
		
	 
		return $rfw_footer_scripts['styles'].implode('', $ret);
	}

Code file location:

rss-feed-widget/rss-feed-widget/inc/functions.php

Conclusion

Now that you’ve learned how to embed the RSS Feed Widget 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 *