Below, you’ll find a detailed guide on how to add the WP Like Button Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the WP Like Button Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the WP Like Button Plugin and the shortcodes it provides:
"WP Like Button is a robust WordPress plugin that enables the addition of customizable 'Like' buttons to your posts, pages, and comments, enhancing user engagement."
- [fblike]
WP Like Button [fblike] Shortcode
The WP-Like-Button plugin shortcode ‘fblike’ adds a Facebook Like button to your WordPress site. It customizes the button’s appearance and placement according to the plugin’s settings. This shortcode uses PHP code to fetch settings data like button size, color, layout, and more. It then generates a ‘like’ button, either for each page or the entire site. It also has mobile compatibility.
Shortcode: [fblike]
Examples and Usage
Basic Example – This shortcode adds a Facebook Like button on your webpage. The parameters for the button such as layout, color, and size are defined in the plugin settings.
[fblike /]
Advanced Examples – The shortcode also allows you to specify additional parameters for further customization.
You can display the Facebook Like button for a specific URL by adding the ‘url’ parameter. The following example shows how to use the shortcode to display a Like button for a specific post or page.
[fblike url="http://yourwebsite.com/your-post-or-page/"/]
Another advanced usage of the shortcode is to specify whether the Like button is displayed on mobile devices or not. By adding the ‘mobile’ parameter and setting it to ‘true’, the Like button will be displayed on mobile devices. If set to ‘false’, it will not be displayed.
[fblike mobile="true"/]
Additionally, you can also specify the position of the Like button on the page by using the ‘position’ parameter. The following example shows how to position the Like button in the center of the page.
[fblike position="center"/]
These are just a few examples of how you can use the ‘fblike’ shortcode to customize the display of the Facebook Like button on your WordPress site. By understanding and utilizing these parameters, you can ensure that the Like button fits seamlessly into your site’s design and functionality.
PHP Function Code
In case you have difficulties debugging what causing issues with [fblike]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('fblike', array($this, 'fb_like_button'));
Shortcode PHP function:
function fb_like_button($content = NULL) {
$post_id = get_the_ID();
$settings = $this->getSettingsData();
$beforeafter = $settings->beforeafter;
$where_like = $settings->where_like;
$status = $settings->status;
$layout = $settings->layout;
$action = $settings->action;
$color = $settings->color;
$btn_size = $settings->btn_size;
$display = $settings->display;
$except_ids = $settings->except_ids;
$language = $settings->language;
$url = $settings->url;
$mobile = $settings->mobile;
$kid = $settings->kid;
$width = $settings->width;
$str = $content;
$share = $settings->share;
$faces = $settings->faces;
$position = $settings->position;
if ($share == 1) {
$share = 'true';
} else {
$share = 'false';
}
if ($faces == 1) {
$faces = 'true';
} else {
$faces = 'false';
}
if ($kid == 1) {
$kid = 'true';
} else {
$kid = 'false';
}
if ($where_like == 'eachpage') {
$actual_link = get_permalink();
} else if ($where_like == 'entiresite') {
$actual_link = get_site_url();
} else {
$actual_link = $url;
}
if (!wp_is_mobile()) {
$fb = '<style>.fb_iframe_widget span{width:460px !important;} .fb_iframe_widget iframe {margin: 0 !important;} .fb_edge_comment_widget { display: none !important; }</style><div style="width:100%; text-align:' . $position . '"><div class="fb-like" style="width:' . $width . 'px; overflow: hidden !important; " data-href="' . $actual_link . '" data-size="' . $btn_size . '" data-colorscheme="' . $color . '" data-width="' . $width . '" data-layout="' . $layout . '" data-action="' . $action . '" data-show-faces="' . $faces . '" data-share="' . $share . '" kid_directed_site="' . $kid . '"></div></div>';
} else if ($mobile && wp_is_mobile()) {
$fb = '<style>.fb-like {overflow: hidden !important;}</style><div style="width:100%; text-align:' . $position . '"><div class="fb-like" style="width:' . $width . 'px" data-href="' . $actual_link . '" data-colorscheme="' . $color . '" data-size="' . $btn_size . '" data-width="' . $width . '" data-layout="' . $layout . '" data-action="' . $action . '" data-show-faces="' . $faces . '" data-share="' . $share . '" kid_directed_site="' . $kid . '"></div></div>
<br>';
}
$width = $settings->width . 'px';
if ($status == 0) {
$str = $content;
} else {
if ($content == NULL) {
$str = $fb;
}
if ($display & 2) {
if (is_page() && !is_front_page()) {
if ($beforeafter == 'before') {
$str = $fb . $content;
} else {
$str = $content . $fb;
}
}
}
if ($display & 1) {
if (is_front_page()) {
if ($beforeafter == 'before') {
$str = $fb . $content;
} else {
$str = $content . $fb;
}
}
}
if ($display & 4) {
if (is_single()) {
if ($beforeafter == 'before') {
$str = $fb . $content;
} else {
$str = $content . $fb;
}
}
}
if ($display & 16) {
if (is_archive()) {
if ($beforeafter == 'before') {
$str = $fb . $content;
} else {
$str = $content . $fb;
}
}
}
}
$except_check = true;
if ($display & 8) {
@$expect_ids_arrays = explode(',', $except_ids);
foreach ($expect_ids_arrays as $id) {
if (trim($id) == $post_id) {
$except_check = false;
}
}
}
if ($except_check) {
return $str;
} else {
return $content;
}
}
Code file location:
wp-like-button/wp-like-button/crudlab-fb-like-button.php
Conclusion
Now that you’ve learned how to embed the WP Like Button Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply