Final version of code used:
function fb_comment_count($link = 'link') {
global $post;
$url="https://graph.facebook.com/";
$posturl = get_permalink($post->ID);
$url .= $posturl;
$filecontent = wp_remote_retrieve_body(wp_remote_get($url, array('sslverify'=>false)));
$json = json_decode($filecontent);
$count = $json->comments;
if ($count == 0 || !isset($count)) {
$count = 0;
}
$comments = $count;
if ($count == 1) {
$comments .= ' Comment';
}
elseif ($count == 0) {
$comments="Leave a Comment";
}
elseif ($count > 1) {
$comments .= ' Comments';
}
if ($link == 'nolink') {
echo $comments;
}
else {
echo '<a href="'.$posturl.'#comments" title="Comments for '.$post->post_title.'">'.$comments.'</a>';
}
}
Related Posts:
- Strip hashtag off permalink with php
- Getting most popular posts based on Facebook comments count
- Disable Attachment Pages Completely
- Display user’s total comment count outside The Loop
- How to output a permanently delete comment link?
- count number of user comments with a specific comment meta value
- Change comments form title on a page by page basis
- How do I make wordpress comment fields required?
- Notify WordPress Site I Have Linked To Them
- Replace comment avatars and links at the same time
- Automatically generate Post/Page from searched Database item?
- Adding ads code between comments
- Featured image fallback link to permalink
- comments_number display outside specified span
- Trying to implement Ajax comments in WordPress, getting WP error
- How does this WordPress Plugin (Thrive Comments) apply their custom comment sort? [closed]
- User’s total comment count excluding comments on their own posts
- 200 Rewrite blog post links
- php script to change slug in post automatically
- Why does my callback function not work with this custom filter hook?
- wp_trim_words() does not work with my code Am I doing any mistake in my code?
- Changes in permalink structure in WordPress and how to apply to in-site links
- WordPress Persistent connection rule does not work for “posts”
- How to use $_GET function WordPress backend
- Ajax load more button for comments wordpress
- wp_head function not outputting
- Create Page To Count Comments For Each Post In WordPress Site
- comments sorting incorrectly across multiple pages
- Create custom permalinks to show Custom Post Type’s relationship?
- wp-comments-post.php file returns a blank page
- Get post id within comments loop
- get_template_directory_uri() providing wrong path for img
- WordPress comment submit button substitutes/options
- How to list commenters and days since last commented
- Function returns post URLs rather than retrieving Facebook Graph API data
- Appended comments but they show up above the content instead of below
- stripping tags from excerpt in WordPress is not working
- get comment data using comment id
- Removing the comment function within wordpress
- Liking a facebook page from wordpress website?
- Fetching Initials of the Commentator in the WordPress Website
- get_comments_number() returns 0
- How can I include the user id inside of a shortcode php output?
- Search only working on front page (index) , not working on other pages
- how to edit a specific post slug using a php code?
- Conditionally load class in the comment section of the post page
- How to get comment_ID by post_ID in wordpress
- WordPress theme showing blank page
- Fatal error: Cannot redeclare comment_theme()
- Can not call .php files after switching to %postname%
- Allow two posts (from different categories) to have the same slug
- Test the existence of a page/article by its URL, taking in consideration the URL rewriting by filters
- comment_post (if comment is approved OR $comment_approved === 1) not working?
- Show all people who commented on all posts by an author
- Custom PHP form needs refresh to load page correctly
- Child-Theme Category View with modified permalinks (%category% removed)
- How to pass parameters in wordpress shortcode?
- Commenting requires wordpress login, wordpress discussion and post comments tick boxes are checked
- Rewrite rule not working, but only when parameter is text
- How does Permalink work with the AMP plugin after Removing Parent Permalink Catalog from Posts
- Get WordPress username to customize url
- Comments on my custom post type
- Post permalink buttons all going to the first post
- WordPress/NGINX not respecting the category URL for new posts
- WordPress generates weird permalinks
- Permalink like example.com/taxonomy/post_type/postname
- What is the proper way to call a function (from functions.php) on a link click?
- Real time notification on user profile after new comment
- How can I output the slug of a comment author?
- redirect 301 with special character like WIX site “#!”
- Facebook like update status for wordpress
- Weird slug in archives permalink
- A Space being added to url generated by custom plugin
- Newly published content gives 404 on wordpress
- set new link as permalink
- Multiple URL from Custom post name
- echo variable containing html and the_permalink();
- WordPress – show number of comments for each post in widget
- append links with unique number string
- How does add_action ‘comment_post’ work?
- How can i call the facebook #hashtag images on my site
- get_permalink returning first letter
- Custom action on comment post
- WordPress most commented posts of last X days
- How to get the rating value of each comment
- How to convert my comment.html to comment.php
- Remove /category/ from category (archive) page URLs (without using a plugin)
- WordPress add parameters with friendly url structure
- Add any username as link prefix and show data from that specific user’s profile on wordpress pages – with no login required
- How to extract URLs from wordpress taxonomies
- why css file not link?how to create permalink?
- Guests comment form – prevent duplicate email addresses
- How to automatically flush permalinks?
- Execute wp_after_insert_post after the permalink is customized
- WordPress CPT & Custom Taxonomy with the SAME Permalink Structure
- Modify the permalink structure for a specific category
- Remove links to the comments section
- WordPress per ACF – permalink is not working
- Processing data and redirecting with query string
- I’ve added SKU to Woocommerce permalinks, but I have small issue