The YouTube Subscribe button shortcode permits you to embed a channel subscription button into your WordPress post or page with shortcode. The button is another good argument for shortcode over code snippets provided by online tools; if the YouTube embed code ever changes, or new features were added, or you simply wanted to alter its appearance, modifying a single function would alter every occurrence of your subscription button on your website. YouTube has altered their code in the past... and they may do again.
The shortcode of
[ytsubscribe layout="full"] will display the following (we've used the full layout for our Flight YT channel).
[ytsubscribe count="hidden" align="right"]. In this case, we've also aligned the button to the right. This will apply a little CSS with padding (defined as a shortcode attribute). We could have optionally aligned left with
[ytsubscribe count="hidden" align="left"]. The button is centered and wrapped in paragraph tags by default.
In the final example, we'll use a full layout in a 'dark' theme for BeliefMedia with the shortcode of
[ytsubscribe theme="dark" layout="full" id="UC3qxAmFHsyqAnrg_UbbsHjQ"]. Note that I've used the attribute of
id. If I were rendering a badge for a
channel by name I would have used
[ytsubscribe theme="dark" layout="full" channel="beliefmedia"]. The result:
We've only just started posting videos to our (lonely) company YouTube channel . While you're here, consider subscribing!
Copy and paste the WordPress function into your theme's
functions.php file or, if you sensibly have one installed, your custom functions plugin. You may optionally download and install our plugin from the bottom of of the page.
The following attributes alter the behaviour of your subscription button.
channelname. If an id is set, the channel will will be overwritten.
idwill overwrite your channel name.
default(just a button) or
full. Defaults to default.
8px 15px 8px 15px. Alter as necessary.
Used outside of WordPress, the following may be used.
Arguments are passed to the function in the
- The most significant cause for confusion when using this shortcode is use of channel name and channel ID. You may only use a vanity (
channel) name if YouTube approved you for such, and your channel is accessible via
youtube.com/yourname. If not, use your channel ID.
- The iframe code we've previously shared should no longer be used. While it may continue to work, it's long deprecated.
- The listen attribute can be used with