1

Basically, here is an idea: I am starting a daily blog, and in order to gain access to sunday's posts, the user needs to share the site. I have figured out how to redirect once someone presses the +1 button, and how to redirect once someone tweets, but I have yet to figure out how to redirect after a facebook like. If anyone can help with this, I'll be very thankful.

For the record, I plan on doing this as whitehat-edly as possible. Basically, the post will say that I'm trying to gain popularity for the site, that I could really use some shares, I'll point out that they get six posts a week without asking for anything, and I'll tell them that I'm fine with them deleting the post if they really don't want to share it.

One other thing, I don't really care if they post it on facebook or not. Like, the code doesn't need to check their facebook page to make sure it worked. I just want it so that when they click the button, it posts, and redirects them. The page won't be hidden, if someone had the direct URL they could get to it without sharing. I just want it to be simple, as I'm an amateur, but I also want to use this to get more traffic and a more engaged audience.

Thanks in advance, Liam

1 Answer 1

3

It's not a simple process, but you can do it with some javascript code.

Not to be shilling or anything, but my plugin Simple Facebook Connect makes this a LOT easier.

Step 1: You need a Facebook Application for your website. SFC guides you through this and configures the javascript on your site.

Step 2: You add some Like buttons. SFC lets you do this automatically or manually with function calls.

Step 3: You add some special javascript code to catch the edge-creation. Here's an example of doing this with SFC:

add_action('sfc_async_init','like_detect_edges');

function like_detect_edges() {
?>
    FB.Event.subscribe("xfbml.render", function() {
        FB.Event.subscribe("edge.create", function(targetUrl) {
            alert('edge.create: '+targetUrl);
        });
        FB.Event.subscribe("edge.remove", function(targetUrl) {
            alert('edge.remove: '+targetUrl);
        });
    });
<?php
}

This adds some code to the initialization phase of the FB javascript such that the like and unlike events will be captured and trigger some javascript code.

Now, I used alert's here, but if you were to change the document.url there, then the page would redirect.

Doing this without SFC is a bit more complex. You have to add your own initialization code, the loader for FB's all.js, the like button XFBML, etc.

1
  • Your plugin no longer exists. Is this still possible?
    – David
    Commented Feb 25, 2016 at 12:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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