keepcalculator

06 Numbers and Powers

Add LinkedIn Share Button in WordPress

Card No. 06·64095 · Updated · Standard formula, shown below

Adding an official LinkedIn share button to your WordPress site lets visitors share your posts and pages on their LinkedIn network with one click, which can increase your content’s reach and drive more traffic. This guide shows you how to add the official LinkedIn Share button using a plugin or a simple code snippet, with no coding experience required for the plugin method. You’ll need a WordPress site (self-hosted or WordPress.com with plugins enabled) and access to the admin dashboard.

What You’ll Need

  • A WordPress site (self-hosted WordPress.org is ideal; WordPress.com plans that allow plugins also work).
  • Admin access to your WordPress dashboard (to install plugins or edit theme files).
  • For the code method: a child theme or a code-snippet plugin (like Code Snippets) to safely add custom code.

Step-by-Step

Method 1: Using a Plugin (Recommended)

  1. Log in to your WordPress admin dashboard.
  2. Go to Plugins → Add New.
  3. In the search box, type “LinkedIn share button” (or “social share buttons”). Press Enter.
  4. Look for a plugin that includes the official LinkedIn Share button (most popular social sharing plugins do). Choose one with good ratings and regular updates, like “Social Warfare” or “AddToAny Share Buttons”. Click Install Now.
  5. After installation, click Activate.
  6. Go to the plugin’s settings page (usually under Settings or a new menu item like Social Warfare).
  7. Find the section where you can choose which social networks to display. Look for LinkedIn and enable it.
  8. Configure where the button should appear: on posts, pages, or both, and choose a position (above or below content, floating, etc.).
  9. Save your changes.
  10. Visit a post on your site to confirm the LinkedIn button appears and works.

Method 2: Adding the Official Code Manually

If you prefer not to use a plugin, you can insert LinkedIn’s official share button code directly. This method gives you full control but requires a bit of technical comfort.

  1. Create a child theme (if you don’t have one) to avoid losing changes when the main theme updates. Or install the “Code Snippets” plugin to add custom PHP safely.
  2. Get the official LinkedIn Share button code from LinkedIn’s developer documentation (search “LinkedIn Share Button documentation”). The code looks like this (but always fetch the latest from LinkedIn):
    <script src="https://platform.linkedin.com/in.js" type="text/javascript">lang: en_US</script>
    <script type="IN/Share" data-url="YOUR_URL"></script>
  3. Replace YOUR_URL with the URL you want to share (e.g., <?php echo get_permalink(); ?> for the current post).
  4. Add this code to your theme’s template file where you want the button to appear. For example, in single.php or content.php, inside the loop, add the code after the post content.
  5. If using Code Snippets, create a new PHP snippet that hooks into the content filter:
    function add_linkedin_share_button($content) {
        if (is_single()) {
            $share_button = '<script src="https://platform.linkedin.com/in.js" type="text/javascript">lang: en_US</script>';
            $share_button .= '<script type="IN/Share" data-url="' . get_permalink() . '"></script>';
            $content .= $share_button;
        }
        return $content;
    }
    add_filter('the_content', 'add_linkedin_share_button');
  6. Save and test your site.

Common Mistakes

  • Placing the code outside the loop: In WordPress, get_permalink() only works inside the loop. If you add the code outside, it may show the wrong URL or nothing.
  • Using a static URL: Hardcoding a specific URL means every post will share that same URL. Use dynamic functions like get_permalink().
  • Forgetting to enqueue scripts properly: If you add the LinkedIn script manually, ensure it’s not loaded multiple times (e.g., on every post in a list). Use wp_enqueue_script or conditionally load it only on single posts.
  • Not testing on mobile: The official button may look different on mobile; test to ensure it’s not cut off.
  • Overloading with too many share buttons: Too many buttons can slow down your site. Choose only the most relevant networks.

Tips

  • Use a caching plugin to improve performance, but make sure to exclude the share button script from caching if it causes issues.
  • Consider adding Open Graph meta tags to control how your content appears when shared on LinkedIn (title, description, image). Many SEO plugins like Yoast or Rank Math do this automatically.
  • Place the button where it’s visible without scrolling, but not intrusive. Above or below the post content is standard.
  • If you use a plugin, keep it updated to ensure compatibility with WordPress and LinkedIn changes.
  • Test the button after any theme or plugin updates.

Troubleshooting

  • Button doesn’t appear: Check that you’ve enabled LinkedIn in the plugin settings and that the button is set to display on the correct post types. Clear any caching plugins or browser cache.
  • Button appears but shares the wrong URL: If using manual code, ensure you’re using get_permalink() inside the loop. If using a plugin, check the plugin’s URL settings (some allow you to override the URL).
  • Button is not clickable or shows a blank space: This often happens if the LinkedIn script fails to load due to a conflict. Try disabling other scripts or plugins to isolate the issue. Also, ensure you’re not blocking external scripts with a security plugin.
  • Button appears but shares the page with no image or title: Add Open Graph meta tags. If you have an SEO plugin, verify the settings. You can test with LinkedIn’s Post Inspector tool.
  • Script errors in the console: Open your browser’s developer tools (F12) and look for errors. Common issues are missing quotes or syntax errors in your custom code.

Frequently Asked Questions

Do I need a LinkedIn developer account to use the official button?

No. The official Share button script works without any API key or developer account. You just include the script and the button markup.

Can I add the button to only certain posts?

Yes. With a plugin, you can often control visibility per post via the editor. With manual code, you can use conditional tags like is_single() or custom fields to show it selectively.

Will the button slow down my site?

The LinkedIn script is external and adds a small overhead. Using a plugin that loads scripts only when needed (e.g., on single posts) minimizes the impact. Use browser caching and asynchronous loading if possible.

Can I style the button to match my theme?

The official button has a fixed appearance, but you can wrap it in a container and apply CSS to adjust spacing or alignment. You cannot change the button’s internal design.

What if the button doesn’t work on my custom post type?

If using a plugin, check its settings to enable the button for custom post types. With manual code, modify the conditional check (e.g., is_singular('your_cpt')).

Is there a way to count shares?

The official button does not display a count. For share counts, you’d need a plugin that uses the LinkedIn Share Count API, but note that LinkedIn has deprecated some count endpoints. Many plugins now show counts only for other networks.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →