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
- Experiences with compiling WordPress using Hip Hop?
- Display user’s total comment count outside The Loop
- how to get permalink structure with php
- 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
- Put a link to a category round a hard coded A HREF
- Add “last” and “first” to WordPress Comment Pagination Links
- Replace comment avatars and links at the same time
- wordpress upgrade has broken my permalinks
- Adding ads code between comments
- How do I fetch all comments per post via WP REST API?
- comments_number display outside specified span
- Trying to implement Ajax comments in WordPress, getting WP error
- Add prefix to link url
- “comments.php” not available after edit in WP administration
- User’s total comment count excluding comments on their own posts
- 200 Rewrite blog post links
- Sending data from custom inputs in WordPress comment form in the admin notification email
- php script to change slug in post automatically
- Show wp_die if url form comment not emply
- 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”
- WordPress every page is 404 not found including admin resources
- How to use $_GET function WordPress backend
- How to implement a rating and review system for WordPress custom posts?
- 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
- Commenting out unwated CSS/scripts in HTML with PHP
- wp-comments-post.php file returns a blank page
- php function to display commenter username or login
- check if comment submitted was successful
- Alter required message using comment form api
- Removing the comment function within wordpress
- Change product_base programmatically
- Divi change project category slug
- Send a mail to specific address in a custom field when a new comment is made on a specific post
- Custom post type permalinks do not appear using the link functions
- How to Handle Going Backwards in Navigation When Referrer in PHP/JavaScript won’t work?
- Remove slugs from custom posts type
- Fetching Initials of the Commentator in the WordPress Website
- .html end of URl affected to SEO?
- How can I include the user id inside of a shortcode php output?
- how to edit a specific post slug using a php code?
- Creating a Category Taxonomy
- Conditionally load class in the comment section of the post page
- Comment_author_url doing nothing
- Fatal error: Cannot redeclare comment_theme()
- OG:Audio facebook meta tags
- Insert PHP code in Text
- Can not call .php files after switching to %postname%
- understand what code is doing when prepending /blog
- Custom URL for multiple categories hierarchy
- 404 on old link after changing post url
- Show all people who commented on all posts by an author
- url not using query string no longer working
- Custom PHP form needs refresh to load page correctly
- Child-Theme Category View with modified permalinks (%category% removed)
- Commenting requires wordpress login, wordpress discussion and post comments tick boxes are checked
- Get WordPress username to customize url
- Fetch commens from a specific post
- Permalink changes after several minutes after saving post
- How to edit button permalink inside function.php using a child theme?
- Closing Comments conditionally in comments.php
- 403 Forbidden Localhost Wamp Apache Php
- How can I output the slug of a comment author?
- How can I enqueue comment-reply script only on certain page?
- How can I add “.html” to the end of a single URL on a WordPress website?
- redirect 301 with special character like WIX site “#!”
- Permalinks and custom PHP application
- Weird slug in archives permalink
- WordPress Rewrite Issue
- Would it be possible to route WordPress Through an MVC Application
- Multiple URL from Custom post name
- WordPress – show number of comments for each post in widget
- How does add_action ‘comment_post’ work?
- WordPress most commented posts of last X days
- Get permalink for a post from inside WordPress and route to a related site
- Facebook php sdk 4 getSessionFromRedirect() always null
- How do I call comments_template(); from a plugin file?
- Make a permalink to the most recent blog post
- SHARING TO FACEBOOK – FROM DYNAMICALLY GENERATED PAGE
- PHP code for link with text
- Remove /category/ from category (archive) page URLs (without using a plugin)
- Accessing WordPress Functions get_permalink() in Vanilla PHP?
- WordPress add parameters with friendly url structure
- how to goto specific page number including title with permalink
- How to extract URLs from wordpress taxonomies
- WordPress 6.1.1 UTF8 Slug Limit Increase
- why css file not link?how to create permalink?
- Guests comment form – prevent duplicate email addresses
- Permissions error when I use my plugin to delete comments in the front-end