Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a WordPress 3.5.1 installation on my WordPress Shack, with the Facebook plugin 1.3.1 installed and the TwentyTwelve 1.1 theme. I have the settings on Facebook - Comments box so that I display the comments box on posts and pages. In Settings - Reading, I checked a static page as front page, "Welcome". I've checked the "Allow comments" checkbox for every page on my site.

However, the Facebook comments box is displayed on every page, except the front page, "Welcome".

This definitely is an issue with the front page, because if I select "latest posts" to display on the front page, the comments box is displayed on the Welcome page.

How can I make that the comments box is displayed on the front page as well?

I of course posted this at the WordPress support forums for Facebook, but I don't get any response.

share|improve this question
    
print_r(get_option('facebook_home_features')); - What do you get for that? –  t f Apr 12 '13 at 18:12
    
@tf it's an empty array. –  Camil Staps Apr 12 '13 at 18:14
    
Hm, okay, this should not be empty, if you selected 'home' for the Comments Box (or any other feature). What about the (regular) pages? print_r(get_option('facebook_page_features')); –  t f Apr 12 '13 at 18:49
    
@tf Ah, but when I select a like button for the homepage, there is an array('like'=>1). However, I cannot select the homepage for the comments box, so I'll guess it's just not possible then. Is there a workaround possible? –  Camil Staps Apr 12 '13 at 18:58
1  
@tf you have done some awesome work, this solves the problem! Can you make this an answer? –  Camil Staps Apr 12 '13 at 19:04
show 1 more comment

4 Answers

up vote 6 down vote accepted
+125

Fast 'n' Hacky

The problem can be solved by changing line 319 in facebook.php to the following:

if (is_home()) {

This way, the front page is not treated as a home page but as a regular page, for which the facebook feature settings can be applied (and will be handled correctly).


More Elegant/Complex

Here is a non-hackish version. Put the following in your functions.php:

add_action('template_redirect', 'force_facebook_comments');
function force_facebook_comments() {
    if (is_front_page()) {
        $features = get_option('facebook_home_features');
        $features['comments'] = true;
        update_option('facebook_home_features', $features);
        add_filter('comments_template', array('Facebook_Comments', 'comments_template'));
    }
    // If you want to handle the 'home' page differently, undo the above stuff
    // elseif (is_home()) {
        // $features = get_option('facebook_home_features');
        // $features['comments'] = false;
        // update_option('facebook_home_features', $features);
        // remove_filter('comments_template', array('Facebook_Comments', 'comments_template'));
    // }
}
share|improve this answer
    
@CamilStaps Okay then, I added a not-hackish version. ;) –  t f Apr 12 '13 at 21:40
    
Thanks! But, you're talking about 'your functions.php' - where do I find that? Facebook doesn't have a functions.php, and I can't find one in the root folder either. –  Camil Staps Apr 13 '13 at 11:03
    
It's part of your theme. And if not, just add the file with only the above code wrapped in <?php ... ?> inside. –  t f Apr 13 '13 at 11:04
    
Ah, thanks! It works :) (and will keep working, even after a facebook update ;)) –  Camil Staps Apr 13 '13 at 11:07
    
That's right. :) But maybe you want to get in touch with the author(s) and suggest to treat home and front-page differently, meaning insert a new option facebook_front_page_features, and also allow the user to select front-page for comments. –  t f Apr 13 '13 at 11:12
show 1 more comment

I don't have the plugin to test this, but looking at the lines to hack, as pointed by @tf:

if ( is_home() || is_front_page() ) {
    $enabled_features = get_option( sprintf( $option_name, 'home' ) );
} else if ( is_archive() ) {
    // all archives wrapped in one option
    // is_post_type_archive || is_date || is_author || is_category || is_tag || is_tax
    $enabled_features = get_option( sprintf( $option_name, 'archive' ) );
} else {
    $post_type = get_post_type();
    if ( $post_type )
        $enabled_features = get_option( sprintf( $option_name, $post_type ) );
}

I think it's possible to short-circuit the third option -} else {- using apply_filters( 'pre_option_' . $option, false );.

Something like:

foreach( array( 'post', 'page' ) as $pt )
    add_filter( "pre_option_facebook_{$pt}_features", "callback" );

function callback()
{
    // let the option work normally
    if( !is_front_page() )
        return false;

    return get_option( 'facebook_home_features' );
}
share|improve this answer
1  
I did not test this, however, nice to know the pre_option_* filter now. Didn't know that before. Then, two things: First, I guess it must be pre_option_facebook_{$pt}_features as the underscore is a valid character for variable names, so the parser will look for the variable $pt_features. Second, don't you want to return get_option('facebook_page_features');? –  t f Apr 12 '13 at 21:51
    
Yep, it was looking strange, corrected. As for the return, I'm not sure about the logic that has to be applied, it has to be adjusted accordingly. When I don't find a initial hook, I go after the functions involved, most of the times there's an entry point ;) –  brasofilo Apr 12 '13 at 21:58
1  
The problem is, the plugin only gives post, page and attachment as options to choose from when setting the comments. Thus, the option *_home_* does not contain the key comments, which is required here. And as Camil wants to treat the front page as a regular page, I chose to use the page option. Anyway: +1. :) –  t f Apr 12 '13 at 22:03
2  
I guess you took a deeper look at the plugin. Nice to see your non hacking the (mini)core solution. –  brasofilo Apr 12 '13 at 22:08
add comment

According to the Template Hierarchy front-page.php or home.php will take precedence over the other pages.

After reviewing the code for the facebook plugin the options there appears to be a different set of options for these cases.

share|improve this answer
    
I'm using Twenty Twelve 1.1. It does not have a front-page.php or home.php template. Any ideas? –  Camil Staps Apr 12 '13 at 17:31
    
I added comments_template('',true) (from single.php) to index.php which most likely generates the front page. However, it's still displaying the same, wrong comments box. –  Camil Staps Apr 12 '13 at 17:33
    
I didn't look at the site until after I posted my answer. I have revised my answer accordingly. –  Steve Buzonas Apr 12 '13 at 17:41
    
Thanks, but I'm not sure what you mean by that - what can I do to make this work? –  Camil Staps Apr 12 '13 at 17:43
add comment

Sounds like it could be theme related. I haven't used Twenty Twelve much, but is the homepage generated from the Appearance > Widget section?

There are a bunch of themes that generate the homepage content based on the corresponding widget. Look in there for a box called Content Left Content Right, Homepage Content or something like that.

This has tripped me up a few times.

You stated there is no front-page.php or home.php, but if I remember correctly there should be a content-home.php that is called from the single.php or page.php.

share|improve this answer
    
There is a post type for the front page, but I'm not using it. The front page is really just a page. Using it removes the default comments box, but doesn't show Facebook's comments box. There is no content-home.php. –  Camil Staps Apr 12 '13 at 18:31
    
Check out the support page for the plugin: wordpress.org/support/topic/… Have you posted a thread there as well? –  ckpepper02 Apr 12 '13 at 19:00
    
Irrelevant, I'm not using a custom template. I posted this thread: wordpress.org/support/topic/comments-on-static-front-page –  Camil Staps Apr 12 '13 at 19:01
    
Ok, if all else fails, I would grab the code from the view source of one of the pages it's working on, and paste it manually in the page template. something like this: if(is_front_page()){ *** paste code here *** } –  ckpepper02 Apr 12 '13 at 19:05
    
Dang!! I type too slow. –  ckpepper02 Apr 12 '13 at 19:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.