• My anime site is run using wordpress and there are some pages that require users to login before they can access the page- the problem with this is that googlebot will also see the page and index the error message.

    How do I treat googlebot as a registered user so it can access the restricted content?

Viewing 5 replies - 1 through 5 (of 5 total)
  • you could check the referrer before the code that secures the page. If it’s googlebot, then don’t secure it.

    it’s not particularly secure, but neither is letting google crawl it, so I guess you’re ok.

    Thread Starter animecut

    (@animecut)

    How would I code that (i’m not very good at php)? At the moment, i’m using a custom template file for my pages that require the user to be logged in.

    well, that really depends on the content of your template – and whether you’re using plugins to secure your pages…

    your initial post makes it sound like you’re comfortable with the code that secures your pages – if you’re not, then what you’re asking isn’t as trivial as I make it sound.

    it won’t do you much good to post your template stuff here. you really need to get a good grasp of how you’re blocking access first.

    this is like asking “how do I let my friends in?” when you have no idea how your door lock works.

    Thread Starter animecut

    (@animecut)

    I’m not using plugins to secure the pages, i’m using this code (and then for the pages I want restricted to logged in users, I just make them use that as the basis of their template).

    <?php if (is_user_logged_in()) {
    // code to display the page goes here

    if (have_posts()) : while (have_posts()) : the_post();

    echo”

    <div class=’entry’>

    “;

    the_content(‘<p class=”serif”>Read the rest of this page »</p>’);

    wp_link_pages(array(‘before’ => ‘<p>Pages: ‘, ‘after’ => ‘</p>’, ‘next_or_number’ => ‘number’));

    echo “</div>”;

    endwhile; endif;

    echo””;
    edit_post_link(‘Edit this entry.’, ‘<p>’, ‘</p>’);

    echo”</div>

    </div>”;

    } else {
    echo”<div class=’top’>AnimeCut > Access Denied</div>”;
    // code to say “you must be logged in to see this page” goes here
    echo”Error: You must login to your account to access this page.If you do not have an account, you can register one here. </div></div>”;
    }

    ?>

    I was obviously on crack earlier when I said ‘referrer’ instead of user agent… after a little nap and a good purge, I’ve come to my senses.

    the stuff you have there for checking whether users are logged in is exceedingly simple, so I’m just going to get you to replace one line of it.

    take the line:

    <?php if (is_user_logged_in()) {

    and replace it with:

    <?php if (is_user_logged_in() || eregi("Googlebot",$_SERVER['HTTP_USER_AGENT'])) {

    that should work a treat. If you want to test it, you’ll have to logout of your wordpress and try accessing your page with your user agent set to googlebot.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Treating googlebot as a registered wordpress user?’ is closed to new replies.