and like us on FB

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).

To display only the subscription button without the count, use [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

Your YouTube channel name. If an id is set, the channel will will be overwritten.

id

Your channel ID. A channel id will overwrite your channel name.

layout

The layout is either default (just a button) or full. Defaults to default.

count

By default your subscriber count will show. To hide, use count="hidden".

theme

The two theme options are default and dark.

listen

By default listen is false. If you build in some JavaScript listeners the code is waiting for you (use listen="1").

align

By default the badge will align to the center in paragraph tags. To float left or right use align="right".

padding

If you align your badge to the left or right, padding applies. Defaults to 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 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 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 With WordPress Shortcode or PHP
Description: Insert a YouTube subscription button with WordPress shortcode or PHP.
Download: Shortcode (V0.2) | WP Plugin (V0.2) | PHP Code (V0.2)

Shortt URL for this post: http://shor.tt/Ar9