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
- How to get URL of current page displayed?
- Disable Attachment Pages Completely
- Experiences with compiling WordPress using Hip Hop?
- Display user’s total comment count outside The Loop
- how to get permalink structure with php
- Getting the comment number relative to all the post’s comments
- 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
- 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?
- Customize Theme comment template to Insert VoteUp and VoteDown buttons
- 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
- WordPress returning 404 for multisite pages
- 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
- edit_comment_link is not showing for comment author
- Limit 1 global comment per minute
- 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
- Create custom permalinks to show Custom Post Type’s relationship?
- wp-comments-post.php file returns a blank page
- php function to display commenter username or login
- Genesis framework comments broken?
- check if comment submitted was successful
- Alter required message using comment form api
- Get post id within comments loop
- How to get post permalink url without a href
- 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
- How to add text to the start of all comments?
- Does anyone know all parameters of get_comments()
- 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?
- Change product_base programmatically
- wp_delete_comment takes two tries to delete – then deletes all comments
- Change “No Comments” link to “My String” on Blog Post (Find Snippet in Code or use CSS, PHP Solution) [closed]
- 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
- get_comments_number() returns 0
- .html end of URl affected to SEO?
- How can I include the user id inside of a shortcode php output?
- Restrict characters in comment section
- Search only working on front page (index) , not working on other pages
- 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
- How to get comment_ID by post_ID in wordpress
- WordPress theme showing blank page
- Comment_author_url doing nothing
- Fatal error: Cannot redeclare comment_theme()
- OG:Audio facebook meta tags
- I don’t have comments.php… how do I customize my comment fields
- Insert PHP code in Text
- Permalinks: site.com/post-tite vs site.com/post-id/post-title for SEO and Speed
- Can not call .php files after switching to %postname%
- WordPress permalink issue
- Change permalink structure specific category
- understand what code is doing when prepending /blog
- Custom URL for multiple categories hierarchy
- WordPress redirects to localhost
- 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?
- 404 on old link after changing post url
- Guests comment form – prevent duplicate email addresses
- Permissions error when I use my plugin to delete comments in the front-end
- Pre_get_comments and orderby comment_karma
- How to automatically flush permalinks?
- Execute wp_after_insert_post after the permalink is customized
- WordPress CPT & Custom Taxonomy with the SAME Permalink Structure
- Remove slug of multiple custom post types with and without hierarchical
- Modify the permalink structure for a specific category
- change the blog in the url if you go from a specific page wordpress
- Is it possible to go to the next post in the same 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
- Removing website URL in comments causes misalignment of submit button and tickbox
- Post returns 404 after changing the permalink using post_type_link
- Cannot access the other pages after successfully editing post type