/    Sign up×
Community /Pin to ProfileBookmark

Adding a logout link to my footer menu

Hi all

I should start by saying I am a complete coding novice!

I currently have this code in my functions.php to control my footer menu:

[CODE]add_filter(‘omega_footer_insert’, ‘my_omega_footer_insert’, 11);

function my_omega_footer_insert( $settings ) {
$year = date( ‘Y’ );
$siteurl = get_bloginfo( ‘url’ );
$sitename = get_bloginfo( ‘name’ );

return “<a href=’http://bibliophone.com/about/’>About</af=’http://bibliophone.com/terms-of-use/’>Terms</a> | <a href=’http://bibliophone.com/privacy-policy/’>Privacy</a><br>© <a href=’$siteurl’>$sitename</a> $year</p>”;
}[/CODE]

That code works fine and appears exactly as I want it to, but I want to add a logout link to this, which displays ONLY when a user is registered and logged in. I have this code:

[CODE]if ( is_user_logged_in() ) {

echo ‘ | <a href=”<?php echo wp_logout_url( get_permalink() ); ?>” title=”Logout”>Logout</a>’;
}[/CODE]

..but I’m not having much luck with it because I don’t know for certain that it’s correct, and secondly I’m not sure where it should be placed within the first bit of code above. Can anyone help please?

Thank you!

Paul

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@abergmanJun 18.2015 — Hello,

It look correct to me, assumed that your is_user_logged_in() actually returns true/false ?
Copy linkTweet thisAlerts:
@NogDogJun 18.2015 — If this is all PHP code, then you have PHP inside of PHP:
[code=php]
<?php

if ( is_user_logged_in() ) {

echo ' | <a href="<?php echo wp_logout_url( get_permalink() ); ?>" title="Logout">Logout</a>';
}
[/code]

What you want to do instead is use concatenation, or exit out of PHP mode then back in, e.g.:
[code=php]
<?php
// ...start of script, then...
if ( is_user_logged_in() ) {
?>
| <a href="<?php echo wp_logout_url( get_permalink() ); ?>" title="Logout">Logout</a>
<?php
}
// rest of script...
[/code]
×

Success!

Help @pmcg911 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...