Jump to content

Help with my functions.php coding to create a logout link


pmcg911

Recommended Posts

Hi all

 

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

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</a> | <a href='http://bibliophone.com/terms-of-use/'>Terms of Use</a> | <a href='http://bibliophone.com/privacy-policy/'>Privacy Policy</a><br>© <a href='$siteurl'>$sitename</a> $year</p>";
}

I want to add a logout link to this, which displays ONLY when a user is registered and logged in. I have this code:

if ( is_user_logged_in() ) {
echo ' | <a href="<?php echo wp_logout_url( get_permalink() ); ?>" title="Logout">Logout</a>';
}

..but I'm not having mu 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

Link to comment
Share on other sites

That functions returns the footer menu as a string, so you cant use echo. You need to concatenate the logout link if the user is logged in. Something like this maybe

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

    $footer = '';

    // prepend logout link to footer
    if(is_logged_in())
        $footer .= '<a href="' . wp_logout_url(get_permalink()) . '" title="Logout">Logout</a> | ';

    $footer .= "<a href='http://bibliophone.com/about/'>About</a> | <a href='http://bibliophone.com/terms-of-use/'>Terms of Use</a> | <a href='http://bibliophone.com/privacy-policy/'>Privacy Policy</a><br>© <a href='$siteurl'>$sitename</a> $year</p>";

   return $footer;
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.