Edit Post Link on WP loop pages elsewhere?
-
Is there any way to allow for the use of certain WP functions outside of the actual WP system?
I have a few pages on my site using just the WP loop but how can I add a working edit_post_link() function to them, and also how can I have a site-wide login/out system?
Basically, if you are outside of the actual WP directory it doesn’t know you’re logged in anymore.
-
Any .php file outside of WP can be made “WP aware” by adding this at the very top (before everything else)
<?php require('./path-to-your-blog/wp-blog-header.php'); ?>Replace “path-to-your-blog” with the real path.
Now you can use any WP function on those files.No I know that, I am using WP everywhere outside of the system but I mean specifically the login/out functionality.
That doesn’t seem to work at all outside of WP. Basically, I can login within the WP system, but if I go outside of it, the pages have no idea I’m still logged in so all my ‘logged in as…’ links change to ‘log in’ again, and I can’t use edit_post_link() because it doesn’t know I’m logged in anymore.
I have asked this before about 5 times in different ways and nobody ever seems to understand or be able to offer a solution. I don’t understand… surely someone’s noticed this before?
I am no good with the logged in/out issue.
However, the second question is nonsense, that’s why nobody gets it. If it is something NOT created by WP – how the heck do you want the “edit_post_link” to work on it? Edit what?
Nonsense? What? Why?
OK… forget the specific edit_post_link() issue. It’s the same problem as the login/out.
You are in the WP directory, and you login. THEN, you go to the Home page of my website, outside of WP. The Home page uses the WP loop to display recent posts or whatever, and on the Home page I need it to still display that you are logged in, but it doesn’t.
It doesn’t know you’re logged in anymore and so you are effectively logged out. Therefore, the posts on the Home page don’t display the edit_post_link() that I have put in them, because you’re not logged in.
If I click on a post, which takes me to a single.php (back in WP) it will show me as logged in. If I go back to the Home page… no longer logged in. And so on.
If I put a loginout() link on the Home page, I can log in but it will be like a separate login. I am logged in to the home page, and the WP system as the same person, at the same time, but completely separately and they have no knowledge of each other.
How is that nonsense? Has nobody ever wanted the website to display you as logged in EVERYWHERE, even outside of WP? If I am including wp-blog-header.php, I thought maybe it would still know I’m logged in.
WordPress sets login cookies specific to it’s own directory. Those cookies don’t get passed along outside of that directory.
You can add define statements for COOKIEPATH and SITECOOKIEPATH to redefine the path those cookies will be in. Then your login cookies will get set and sent to that new path, making you logged in from there as well.
A cookie path is site-root-relative. Meaning that if your site is in http://example.com/blog/ , then the cookie path is /blog/ . If you redefine that to just /, then you’ll be logged in at the root too.
When you change these, you need to clear your cookies and relogin to see any effect.
Excellent, thanks.
Where are those constants defined in the first place, and where is the best place for me to change them or add the definitions if they don’t exist yet?
They are not defined anywhere. Those constants override the internal settings, which are figured out automatically.
The best place to add them is the wp-config.php file.
Finally! Brilliant, this works perfectly.
Your help is much appreciated. I have been trying to sort this out for so long.
@otto42 – it sounds great and very neat
but what if the blog is actually in a subdomain?
is there a way to trick it?i have been reading http://codex.ww.wp.xz.cn/WordPress_Cookies and http://codex.ww.wp.xz.cn/Login_Trouble in search of a starting point but couldn’t find any – so any pinters would be nice
just finaly found out that:
define(‘COOKIE_DOMAIN’, ‘.domain.com’);would work for subdomains – one needs to have the . in front of the domain name to make it behave the way it “should”
I’ve tried the suggestions above and variations of those suggestions with no luck. I’d really appreciate if someone could look at my site and have some specific instruction for me. I’m having the same difficulty (sounds like a cookie problem), in that my site doesn’t recognize that I’m logged in.
The site is
http://www.mophojo.com
it lives as a subdomain and the wp install is
http://www.davidstephenson.com/mophojoI’m hoping that someone who understand cookies well can look at my site’s cookies and see where the defined path is messed up.
Many thanks.
Thanks everyone! This is a nice hack, but the functionality it enables (login detection) is actually ESSENTIAL to anyone who’s got WP installed in a different directory than the blog url.
Which makes you wonder: Why isn’t this trick (or the equivalent) described IN THE OFFICIAL DOCUMENTATION (SEE ABOVE)?
It’s nice of the ww.wp.xz.cn team to tell us about giving WordPress its own folder, but without the cookie hack here, people are going to be VERY FRUSTRATED they can’t get edit_post_link() and wp_loginout() to work!
Please merge this hack into the codex!
The topic ‘Edit Post Link on WP loop pages elsewhere?’ is closed to new replies.