RBA Cash Rate: 4.35% · 1AUD = 0.67 USD · Inflation: 4.1%  
Leading Digital Marketing Experts | 1300 235 433 | Aggregation Enquires Welcome | Book Appointment
Example Interest Rates: Home Loan Variable: 5.20% (5.24%*) • Home Loan Fixed: 5.48% (6.24%*) • Fixed: 5.48% (6.24%*) • Variable: 5.20% (5.24%*) • Investment IO: 5.63% (6.88%*) • Investment PI: 5.49% (6.32%*)

Embed A LinkedIn Video Or Post In WordPress With Shortcode

Embed A LinkedIn Video Or Post In WordPress With Shortcode

Of all the LinkedIn LinkedIn shortcodes WordPress Shortcode we've shared in the past, this would have to be the most pointless. However, because our own company policy dictates we never use 'default' embed code for anything, we wrote a shortcode to embed LinkedIn posts some time back.

The nature of LinkedIn embeds means that the height of the embedded content is a variable. So since there's no means of determining what that height should be without looking at the iframe embed code, it must be defined in every single shortcode we use. The width tends to be fixed at 504 pixels but that's also something that might change from post-to-post. The usefulness of shortcodes comes from using as few attributes in the code as possible, and it's the inclusion of the height that makes this particular shortcode a little annoying.

Our shortcode really doesn't do much other than center the content in your WordPress post container, and it provides a future-proof means of altering the embed code should it ever change in the future.

The Result

The result is the same as simply embedding the naked embed code. The shortcode of [linkedin id="urn:li:ugcPost:6449845260351836160" height="578"] returns the video post below. Note that we've included the post ID and the height. You may optionally include the full post URL although we'd recommend against it. If the width is anything other than 504 you'll have to also include the width as a shortcode attribute.

■ ■ ■

Widget included with a shortcode as provided here.

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.

1
<?php 
2
/*
3
 Embed A LinkedIn Video Or Post In WordPress With Shortcode
4
 https://www.beliefmedia.com.au/embed-linkedin-wordpress
5
*/
6
 
7
8
 
9
  $atts = shortcode_atts(array(
10
    'url' => '',
11
    'width' => '504',
12
    'height' => 0
13
  ), $atts);
14
 
15
  /* Group URL required */
16
  if ( (!$atts['url']) || (!$atts['height']) ) return 'A valid post URL and height is required.';
17
 
18
  if (strripos($atts['url'], 'https://') !== false) {
19
    $arr = explode('/', $atts['url']);
20
    $atts['url'] = end($arr);
21
  }
22
 
23
  /* Embed code */
24
  return '<div style="text-align: center;"><iframe src="https://www.linkedin.com/embed/feed/update/' . $atts['url'] . '" height="' . $atts['height'] . '" width="' . $atts['width'] . '" frameborder="0" allowfullscreen=""></iframe></div>';
25
}
26
add_shortcode('linkedin', 'beliefmedia_embed_linkedin_wordpress');

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 shortcode attributes apply.

url

The url is either the full post URL or the post ID (at the end of the URL string). For future-proofing purposes it's best just to use the ID.

height

As stated, because the height of the LinkedIn embed container is a variable, it must be included.

width

The width of the embed container is usually 504 pixels. If anything else, include it into the shortcode as an attribute (eg: width="518").

Considerations

  • The LinkedIn embed container is responsible on mobile devices by default.
  • We will share another version shortly that automatically determines height and width, but it's a little more complex.
  • LinkedIn URN namespace information can be found here .

Download


Title: Embed LinkedIn Content In WordPress With Shortcode
Description: Embed A LinkedIn Video Or Post In WordPress With Shortcode.
  Download • Version 0.1, 666.0B, zip, Category: WordPress Shortcodes

Download our 650-page guide on Finance Marketing. We'll show you exactly how we generate Billions in volume for our clients.

  AUS Eastern Standard Time (Connecticut)

  Want to have a chat?
 

RELATED READING

Like this article?

Share on Facebook
Share on Twitter
Share on Linkdin
Share on Pinterest

Leave a comment