Below, you’ll find a detailed guide on how to add the YouTube Subscribe 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 YouTube Subscribe Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the YouTube Subscribe Plugin and the shortcodes it provides:
"YouTube Subscribe is a user-friendly WordPress plugin that allows you to seamlessly integrate a YouTube subscription button into your website. Boost your channel's followers with Easy YouTube Subscribe."
- [sm-youtube-subscribe]
YouTube Subscribe [sm-youtube-subscribe] Shortcode
The Easy YouTube Subscribe shortcode adds a customizable YouTube subscription button to your WordPress site. The shortcode fetches the channel ID, layout, theme, and count from the plugin’s settings. It then uses these elements to generate a YouTube subscription button with the specified attributes. The button is wrapped in a container with a theme-based class for additional styling.
Shortcode: [sm-youtube-subscribe]
Examples and Usage
Basic example – A simple usage of the ‘sm-youtube-subscribe’ shortcode to display the YouTube subscribe button on your page.
[sm-youtube-subscribe /]
Advanced examples
Using the shortcode to display the YouTube subscribe button with a specific channel ID. The channel ID is a unique identifier for a YouTube channel, and using this parameter will ensure that the subscribe button is linked to the correct channel.
[sm-youtube-subscribe sm_youtube_channel_id="UC_x5XG1OV2P6uZZ5FSM9Ttw" /]
Using the shortcode to display the YouTube subscribe button with a custom layout and theme. The ‘sm_full_layout’ parameter can be set to ‘full’ for a larger button, and the ‘sm_dark_theme’ parameter can be set to ‘dark’ for a dark-themed button. The subscriber count can also be hidden by setting the ‘sm_subscriber_count_hide’ parameter to ‘hidden’.
[sm-youtube-subscribe sm_full_layout="full" sm_dark_theme="dark" sm_subscriber_count_hide="hidden" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [sm-youtube-subscribe]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'sm-youtube-subscribe', 'sm_youtube_subscribe_shortcode' );
Shortcode PHP function:
function sm_youtube_subscribe_shortcode( $atts ){
global $wp;
$current_url = home_url(add_query_arg(array(),$wp->request));
$instance = get_option( 'sm_youtube_subscribe_options' );
$title = ($instance['title'])?$instance['title']:'';
$channel_id = ($instance['sm_youtube_channel_id'])?$instance['sm_youtube_channel_id']:'UCKIG1BY9SOv2Hg1q5I8WLBQ';
$layout = ($instance['sm_full_layout'])?'full':'default';
$theme = ($instance['sm_dark_theme'])?'dark':'default';
$count = ($instance['sm_subscriber_count_hide'])?'hidden':'default';
ob_start();
?>
<style type="text/css">
.dark_theme{
padding: 8px;
background: rgb(85, 85, 85);
}
</style>
<div class="ytsubscribe_container <?php echo $theme; ?>_theme">
<script src="https://apis.google.com/js/platform.js"></script>
<?php if($title):?>
<h3><?= $title;?></h3>
<?php endif;?>
<div
class="g-ytsubscribe"
data-channelid="<?php echo $channel_id; ?>"
data-layout="<?php echo $layout; ?>"
data-theme="<?php echo $theme; ?>"
data-count="<?php echo $count; ?>">
</div>
</div>
<?php
return ob_get_clean();
}
Code file location:
easy-youtube-subscribe/easy-youtube-subscribe/includes/sm-youtube-subscription-shortcode.php
Conclusion
Now that you’ve learned how to embed the YouTube Subscribe 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.
Leave a Reply