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 Result
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!
WordPress Shortcode
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.
If you require shortcode to work in a sidebar widget, you'll have to enable the functionality with a filter. If you're using our custom functions plugin, you'll have that feature enabled by default.
Shortcode Attributes
The following attributes alter the behaviour of your subscription button.
channel
channel
name. If an id is set, the channel will will be overwritten.id
id
will overwrite your channel name.layout
default
(just a button) or full
. Defaults to default.count
count="hidden"
.theme
default
and dark
. listen
listen="1"
).align
align="right"
.padding
8px 15px 8px 15px
. Alter as necessary.PHP Function
Used outside of WordPress, the following may be used.
Arguments are passed to the function in the $args
array.
Considerations
- 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 viayoutube.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
listen="1"
. It specifies the name of a JavaScript function that will handle event notifications related to the button. More info here .
Download
Title: YouTube Subscribe Button in WordPress (WP Plugin)
Description: Insert a YouTube subscription button with WordPress shortcode or PHP.
Download • Version 0.2, 1.8K, zip, Category: WordPress Plugins (General)
WordPress Shortcodes, (959.0B) PHP Code & Snippets, (1.0K)