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

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;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.