latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Need to add logout link on php page

Home Forums Community Forum Need to add logout link on php page

Tagged: 

This topic contains 6 replies, has 3 voices. Last updated by  Mike Waller 3 years, 6 months ago.

Topic Author Topic
Posted: Thursday Jun 27th, 2013 at 6:21 pm #52703
Mike Waller
Username: seozones

Hi there. I have a site using s2member pro and I’ve placed the following in the header.php page but the logout link is not working. I’ve tried…

< ?php
if ( is_user_logged_in() ) {
echo '<a href="” title=”Logout2″>Logout’; }
else {
echo ‘Login‘;}
?>

and this…

< ?php
if ( is_user_logged_in() ) {
echo '<a href="&redirect_to=%2Floggedout%2F”>Logout’; }
else {
echo ‘Login‘;}
?>

but it goes to a 404 error page. I also would like to add this code to a page and have downloaded and activated a couple of plugins that allow for adding php inside the page but that doesn’t work after I publish the page.

Any ideas?

List Of Topic Replies

Viewing 6 replies - 1 through 6 (of 6 total)
Author Replies
Author Replies
Posted: Friday Jun 28th, 2013 at 6:17 am #52729
Bruce
Username: Bruce
Staff Member

Thank you for your inquiry.

You can get the logout URL for your site using the wp_logout_url() function documented here:

http://codex.wordpress.org/Function_Reference/wp_logout_url

Will that work for you?

Posted: Friday Jun 28th, 2013 at 9:06 am #52736
Mike Waller
Username: seozones

hi there. i tried but it doesn’t work and goes to an error page. This is the url it redirects to:

http://149.47.182.178/%3C?php%20echo%20wp_logout_url(%20home_url()%20);%20?%3E

Seems that something is not being translated correctly. Also, I’m working on an ip not a domain, does that matter?

Posted: Friday Jun 28th, 2013 at 9:59 pm #52771

Are you using [hilite mono]wp_logout_url[/hilite] or something else? That address you get has PHP code that wasn’t parsed because some symbols where encoded, which shouldn’t happen.

If you’re using PHP in a WP post/page, don’t use the Visual editor or it’ll corrupt the code. Only use the Text tab of the editor for PHP code. And you’ll need a PHP execution plugin (e.g. ezPHP).

Posted: Saturday Jun 29th, 2013 at 1:08 am #52789
Mike Waller
Username: seozones

Okay, I did get that to work on my wordpress page but in my header.php page, it won’t work. In my header.php page I have the same code as inside my wp page which is:

<?php
if ( is_user_logged_in() ) {
echo '<a href="<?php echo wp_logout_url( home_url() ); ?>" title="Logout"><img src="/images/logout-bottom.png" alt="" width="120" height="23" border="0" /></a>'; }
else {
echo '<a href="/wp-login.php"><img src="/images/login-bottom.png" alt="" width="120" height="23" border="0" /></a>';}
?>

I also have the plugin PHP Execution installed as well as Exec-PHP wp plugin.

Posted: Saturday Jun 29th, 2013 at 4:54 am #52795
Bruce
Username: Bruce
Staff Member

Okay, I did get that to work on my wordpress page but in my header.php page, it won’t work. In my header.php page I have the same code as inside my wp page which is:

The problem with this code is that you’re using PHP tags to echo the value inside of a PHP echo. Try this:

<?php
if ( is_user_logged_in() ) {
echo '<a href="' . wp_logout_url( home_url() ) . '" title="Logout"><img src="/images/logout-bottom.png" alt="" width="120" height="23" border="0" /></a>'; }
else {
echo '<a href="/wp-login.php"><img src="/images/login-bottom.png" alt="" width="120" height="23" border="0" /></a>';}
?>
Posted: Saturday Jun 29th, 2013 at 10:33 am #52801
Mike Waller
Username: seozones

That worked, thanks Bruce!

Viewing 6 replies - 1 through 6 (of 6 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.