RBA Cash Rate: 4.35% · 1AUD = 0.67 USD · Inflation: 4.1%  
Leading Digital Marketing Experts</strong | 1300 235 433 | Aggregation Enquires Welcome | Book Appointment
Example Interest Rates: Home Loan Variable: 5.69% (5.89%*) • Home Loan Fixed: 5.39% (6.59%*) • Fixed: 5.39% (6.59%*) • Variable: 5.69% (5.89%*) • Investment IO: 5.69% (6.48%*) • Investment PI: 5.39% (6.59%*)

Add a LinkedIn Share Button To WordPress With Shortcode

Add a LinkedIn Share Button To WordPress With Shortcode

This quick article will show you how to include a LinkedIn 'Share Widget' into your WordPress post or page with shortcode. The small snippet of JavaScript the function returns is minimal, but shortcode is still the most efficient means of returning the same snippet of code or text in multiple locations. If LinkedIn were to alter their widget code, as they often do, you would only correct a single function to alter every occurrence of the widget code on your website.

The Result

The shortcode of [linkedinshare] returns the following:

If you were to include the widget wrapped into paragraph text, use [linkedinshare align="right"]. The result:

When aligning left or right you may also alter the padding around the widget. The share page and language may also be altered (as described below).

Shortcode Function

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
 Add a LinkedIn Share Button To WordPress With Shortcode
4
 https://www.beliefmedia.com.au/linkedin-share-wordpress
5
*/
6
 
7
function beliefmedia_linkedin_share($atts) {
8
 
9
  $atts = shortcode_atts(array(
10
    'lang' => 'en_US',
11
    'url' => false,
12
    'padding' => '8px 15px 8px 15px',
13
    'align' => false,
14
  ), $atts);
15
 
16
   global $post;
17
 
18
   /* URL */
19
   $url = ($atts['url'] !== false) ? $atts['url']  : get_permalink($post->ID);
20
 
21
   /* Style */
22
   $css = ($atts['align'] !== false) ? 'float: ' . $atts['align'] . '; padding:' . $atts['padding'] : 'text-align:center;';
23
 
24
   $return = '<script src="//platform.linkedin.com/in.js" type="text/javascript"> lang: ' . $atts['lang'] . '</script>
25
   <script type="IN/Share" data-url="' . $url . '"></script>';
26
 
27
 return '<div id="linkedin-share" style="' . $css . '">' . $return . '</div>';
28
}
29
add_shortcode('linkedinshare', 'beliefmedia_linkedin_share');

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 are available:

lang

Alter the language to any other that's supported by LinkedIn.

url

To share any URL other than the current page, reference the URL in your shortcode. Example: [linkedinshare url="http://www.beliefmedia.com/"]

padding

If the widget is aligned left or right you may alter the padding as required. If left as false, we'll simply center it.

align

Alignment can be left or right. The widget will center by default.

Download


Title: Add a LinkedIn Share Button To WordPress With Shortcode
Description: Add a LinkedIn share button To WordPress with shortcode. Attributes to alter the URL & styling.
  Download • Version 0.1, 682.0B, zip, Category: WordPress Shortcodes

■ ■ ■

 
Download our complimentary 650-page guide on marketing for mortgage brokers. We'll show you exactly how we generate billions in volume for our clients.
Finance Guide, Cropped Top and Bottom
  Timezone: 1 · [ CHANGE ]

RELATED READING

Like this article?

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

Leave a comment