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.69% (5.89%*) • Home Loan Fixed: 5.48% (6.24%*) • Fixed: 5.48% (6.24%*) • Variable: 5.69% (5.89%*) • Investment IO: 5.74% (6.40%*) • Investment PI: 5.49% (6.27%*)

Embed A Facebook Comment In WordPress With Shortcode

Embed A Facebook Comment In WordPress With Shortcode

This article will show you how to include a Facebook Embedded Comment into a WordPress post or page with shortcode.

Embedding a comment is one of those features that's becoming more and more popular - particularly in the news-starved world of traditional media where they'll often use social posts as an alternative to genuine editorial content. If you're looking to add social proof or feedback from a conversation, or you would simply like to include the input of others in your own editorials, the Facebook plugin works very well.

The comments plugin will have the effect of increasing engagement with your Facebook post... although it does (at times) compromise on page-load times.

The Result

Here's a comment of us whinging about Telstra's crappy ADSL broadband speeds. Shortcode used is [fbcomment url="https://www.facebook.com/beli (snip) 239792483&comment_tracking=%7B%22tn%22%3A%22R%22%7D"].

In this second example I'll include a single comment I made on Facebook some time ago, and I'll include the parent comment (note that you can't include the parent post). Our shortcode uses the additional parameter of parent="1" to include the parent comment.

The Comment Link

To obtain the required comment URL, copy the link associated with the date published below a comment.

Facebook Comment Link

You may optionally click on this link and copy the resulting browser URL to your shortcode.

Shortcode Attributes

url

The absolute URL of the comment.

width

The width of the embedded comment container. Min. 220px. Defaults to 560px on desktop. On mobile this parameter is ignored and the width is always 100% (fluid width). Alter as follow: width="400".

parent

Set to true (parent="1") to include the parent comment (if the URL is a reply). You cannot include the parent post.

WordPress Shortcode

Usage of the function requires the Facebook SDK code be copied to your website.

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 Facebook Comment In WordPress With Shortcode
4
 https://www.beliefmedia.com.au/facebook-comment-shortcode
5
*/
6
 
7
8
 
9
  $atts = shortcode_atts(array(
10
    'url' => false,
11
    'width' => '560',
12
    'parent' => 0,
13
  ), $atts);
14
 
15
  /* If URL is empty */
16
  if (!$atts['url']) return 'Comment URL cannot be empty.';
17
 
18
  /* Boolean as string (corrent for parent="1") */
19
  $atts['parent'] = (!$atts['parent']) ? 'false' : 'true';
20
 
21
  /* Build result */
22
  $return = '<div class="fb-comment-embed" data-href="' . $atts['url'] . '"';
23
  $return .= ' data-width="' . $atts['width'] . '" data-include-parent="' . $atts['parent'] . '"></div>';
24
 
25
  /* Wrap in our own DIV and
26
 
27
 tags */
28
  $result = '<div style="text-align:center;">' . $return . '</div>';
29
 
30
 return $result;
31
}
32
add_shortcode('fbcomment', 'beliefmedia_embed_facebook_comment');

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.

Embedding iFrames

As with most of Facebook's content, you can simply copy embed code and paste it directly into your post. As with all Facebook features, the comment plugin functionality changes as often as Oprah does drive-through McDonald's so we'd suggest always using shortcode so you can globally alter all embedded occurrences should the need present itself. That said, if you were to use the iframe option, you would simply copy the code as detailed below.

Facebook Embed Comment

Click embed and Facebook will launch a modal with your embed code. Copy it directly into your WordPress website.

Facebook Embed Code

The iframe option negates the need to have the Facebook SDK code copied to your webiste.

Considerations

Download


Title: Facebook Comment Plugin (WordPress Shortcode)
Description: Embed A Facebook Comment In WordPress With Shortcode. Optionally include parent comment.
  Download • Version 0.1, 670.0B, zip, Category: WordPress Shortcodes
PHP Code & Snippets, (5.1K)    

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

  E. Australia Standard Time [ UTC+10, Default ] [ CHECK TO CHANGE ]

  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