Archived topic
Adding a hook
9 replies · Started by Engelbrecht on August 2, 2018
Hi GP team,
I want to add this function (add'ed it in the funciton.php) to show if the user is logged in and their name but it does not look well.
function bba_generate_inside_secondary_navigation() {
$current_user = wp_get_current_user();
if ( 0 == $current_user->ID ) {
// Not logged in.
echo 'Hej. Du er ikke logget ind. Log ind';
} else
{
if($current_user->user_firstname)
{
echo 'Logget ind som: ' . $current_user->user_firstname . '. Log ud?';
} else
{
echo 'Logget ind som: ' . $current_user->display_name . '. Log ud?';
};
}
}
add_action( 'generate_inside_secondary_navigation','bba_generate_inside_secondary_navigation' );
I want it to be part of the secondary menu, and should be aligned left of the secondary navigation. Not all to the left, just at the beginning of the menu. Right now it stacks the above code and on mobile its not in the menu, but above hamburger menu. Any idea how to solve this?
Hi there,
as a non logged in user i am seeing the code being output to the secondary menu.
Can you fix this first? If you need help, please paste you're code back here and use the Code tags button to wrap the code.
Yes, but im not sure why its being printet.
function bba_generate_inside_secondary_navigation() {
$current_user = wp_get_current_user();
if ( 0 == $current_user->ID ) {
// Not logged in.
echo 'Hej. Du er ikke logget ind. <a href="/login/"> Log ind</a>';
} else
{
if($current_user->user_firstname)
{
echo 'Logget ind som: ' . $current_user->user_firstname . '.<a href="/logout/"> Log ud?</a>';
} else
{
echo 'Logget ind som: ' . $current_user->display_name . '.<a href="/logout/"> Log ud?</a>';
};
}
}
add_action( 'generate_inside_secondary_navigation','bba_generate_inside_secondary_navigation' );
Ive used this in my previous theme without problem.
Hi there,
ok so that code works, can you try re-adding the code and then i can help with the CSS.
Its re-added now!
Ok so that works, this CSS should get them all in line
.secondary-navigation .inside-navigation {
display: -webkit-inline-box;
display: -ms-inline-flexbox;
display: inline-flex;
}
Thank you David, however the css makes the whole menu move out of the container area. Got full width on navigations but inner is a container.
I really need to learn css :)
Hi there,
Did you remove the code? Not sure I'm seeing what that code should be adding.
Let me know :)
Hi Tom,
Yes i wasent sure if it would work and im having a graphic designer creating a logo, so i dont want to clutter the website yet.
Im not sure im gonna go forward with it. Can't seem to get the spacing right either. Like the hook removes spacing, so i tried with html entities like but without succes.
Let us know if you do want to go ahead :)