3

I am working on anew blog. I am logged in as administrator, and above every post there is a option to 'edit this entry'.

Can I have WordPress set up so that even is I am logged in as administrator, I will still view the front end of the website as if I was not logged in. This was I can see how the user would see the page.

One option is to just view the website in another browser, but I guess there has to be another page.

2
  • Use a differenty browser where you do not login... so you will see the site as non logged in... usually it's the way i use...
    – SteveAgl
    Oct 25, 2011 at 15:02
  • Thank you for this answer, but as I said in the question, I knew this already. I prefer working in one browser tho. thanks anyway. Oct 25, 2011 at 15:06

6 Answers 6

0

See this related question. You should be able to add this code to your themes functions.php

   add_filter( 'edit_post_link', '__return_false' );
0
4

Those edit links are Theme-dependent, via the edit_post_link() template tag. However, there are several other, similar variances in site appearance between logged-in and non-logged-in users: the presence of the Admin bar, edit-post links, edit-comment links, login/logout/register links (added directly to the template, or via Widget), etc.

These don't really constitute "front-end editing"; they're just links that appear (or change) based on the logged-in status of the user.

Your best bet, most likely, is to view the site in a browser from which you are not logged-in to your site.

1
  • +1. Common sense FTW. There's so many difference between logged in or not, and each plugin can have it's own differences, that opening a new browser is THE ONLY real way to see it as not logged in. Oct 25, 2011 at 22:31
2

Turn on Privacy or Incognito mode, or use another browser, it's the only reliable way of doing it. People may give you filters that may get rid of one thing ro another but there'll never be a 100% perfect code fix.

Asking for a solution that allows you to view the frontend as if your not logged in introduces a whole new raft of issues such as people not being able to login and comment as it won't remember them, etc

What you're asking for is essentially "I have a car and I want to drive around but I don't want to do it using wheels, how do I add tank treads?" It's doable but its not really the solution.

1
  • Google Incognito Window is indispensable. Open IW for a fresh session, close it and reopen to clear the cookies and start over again. Oct 25, 2011 at 22:59
1

You can conditionally nuke global variable with user info, something like this:

function no_user() {

    global $current_user;

    if( is_admin() )
        return;

    $current_user = -1;
}

I don't know precisely which is most appropriate moment to do this. Doing this on template_redirect should be early enough to cancel it out for most (if not all) things in templates.

Also I went with -1 for the sake of it being not empty (which will trigger it being re-setup on calls of some related function) but it probably would be better to set it up with info of existing non-privileged user.

1
  • +1 Oh this is interesting. I will try this out the next time, for now BandonRandon's answer is is enough. Maybe when I get into a further stage of development this will be handy. Oct 25, 2011 at 19:04
0

I've created a plugin that let's you view your website as a visitor without switching browsers plus a lot more (user switching, role switching, default screen settings, role manager, etc.).

Hope it can help you as well: https://wordpress.org/plugins/view-admin-as/

0

Just kill the user variable at the first possible moment:

add_action( 'set_current_user', 'kill_user', 999999 );

function kill_user() {

    global $current_user;

    $current_user = new WP_User();

}

I've used a high number for priority in case any other hooks do something here. Also the variable cannot just be false or empty because later functions expect this to be a WP_User object ...

Thanks goes to Rarst and his answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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