Note: With changes to Facebook's API, the code on this page may not work. We'll review it soon.
This article will show you how to include your Facebook page likes in plain text with WordPress shortcode, a PHP function, or with our WordPress plugin. This is the first of quite a few articles that'll show you how to include the counts of various social networks in your websites via various means. This function requires that you register a Facebook application (don't worry, it's easy). Follow the steps as described here.
As an example, the count for our Flight Facebook page, using the shortcode of [fblikes id="flightorg"]
, is Unavailable (bolding is mine). We've cached the result for 12 hours and applied number formatting by default (details below). The sad count for BeliefMedia's page is Unavailable (we're yet to promote it in any way).
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.
WP Plugin
If you download our plugin you'll find the menu to update all options under Tools
-> BeliefMedia Facebook Counts
.
Any attributes supplied in your shortcode will overwrite the options saved to your database (normally just the Facebook page ID).
PHP Function
Used outside of WordPress, the following PHP function may be used. Usage requires Simple Cache (to cache data and avoid repeated and lengthy requests to Facebook).
Arguments are passed to the function in an $args
array.
Considerations
- You might consider rendering the result as an image. There are any number of ways of achieving this - notably with GD or ImageMagick. This very simple example renders each digit as an image.
- Using our textbox shortcode you can include the count in a nicely formatted manner.
or...
- If you download the plugin we'll provide you with update notifications via your dashboard. We expect to build lots of features into this plugin, such as the image feature described above.
Download
Title: Count Facebook Page Likes with WP Shortcode (Shortcode)
Description: Display a count of FB page likes in plain text with shortcode. Requires the creation of an application.
Download • Version 0.3, 796.0B, zip, Category: WordPress Shortcodes
WordPress Plugins (General), (4.5K) PHP Code & Snippets, (894.0B)