How could I move

How could I move the “Min Profil” link, as a submenu of another menu item, at the top position? [More details in the live chat notes]

  • Kasia Swiderska
    • Support nomad

    Hello Robin,

    Please try this code:

    function wpmudev_movemenuitem() {
    ?>

    <script type="text/javascript">
    jQuery( document ).ready(function($) {
    var last = $("#menu-meny li").last();
    $(last).detach().prependTo('#menu-item-127 .sub-menu').addClass('ion-ios-arrow-thin-right');
    });
    </script>

    <?
    }
    add_action( 'wp_footer', 'wpmudev_movemenuitem' );

    you can add it to functions.php file of your child theme or use as Must Use plugin https://codex.wordpress.org/Must_Use_Plugins

    let me know if this works.

    kind regards,

    Kasia

  • Kasia Swiderska
    • Support nomad

    Hello Robin,

    Please try this version – it should only fire code when user is logged in so users not logged in won’t be affected

    function wpmudev_movemenuitem() {
    if ( is_user_logged_in() ) {

    ?>

    <script type="text/javascript">
    jQuery( document ).ready(function($) {
    var last = $("#menu-meny li").last();
    $(last).detach().prependTo('#menu-item-127 .sub-menu').addClass('ion-ios-arrow-thin-right');
    });
    </script>

    <?

    }
    }
    add_action( 'wp_footer', 'wpmudev_movemenuitem' );

    kind regards,

    Kasia

  • Robin
    • WPMU DEV Initiate

    Hi Kasia! I really thought we had it now so I uploaded it to my live site, but then I noticed it is displaying "Min Profil" in every menu at the site, see the attached .pngs.

    Any way to have it only showing at the top meny?

    Thanks again!!

    Robin

  • Robin
    • WPMU DEV Initiate

    Hi Kasia – thanks for your reply!

    Oh, I see. I kept some of the old code because the latest version you sent, alone, moves the link to Log out “Logga Ut” from the bottom of the list to the top (see the attached image from /pnrstage4 where I evaluate this). By keeping the following code as well, the link is appropriately set to My Profile, but it also makes the link appear in every menu. Maybe you can help me combine these two codes properly? :slight_smile:

    function my_nav_menu_author_link( $menu )

    {

    if( !is_user_logged_in() ){

    return $menu;

    } else {

    $link = get_author_posts_url( get_current_user_id() );

    $class = is_author() ? ‘ class=”current-menu-item”‘ : ”;

    $author_archive_link =

    ‘<li’ . $class . ‘>’ .

    ‘ .

    __( ‘Min Profil’ ) .

    ‘ .

    ”;

    $menu = $menu . $author_archive_link;

    return $menu;

    }

    }

    add_filter( ‘wp_nav_menu_items’, ‘my_nav_menu_author_link’ );

    Thanks again!

    Robin

  • Robin
    • WPMU DEV Initiate

    Hi!

    Absolutely. The code is already in the child’s functions.php at https://partnerinride.se/pnrstage4 which you can access with

    //removed creds by staff

    This is the complete code:

    function my_nav_menu_author_link( $menu )

    {

    if( !is_user_logged_in() ){

    return $menu;

    } else {

    $link = get_author_posts_url( get_current_user_id() );

    $class = is_author() ? ‘ class=”current-menu-item”‘ : ”;

    $author_archive_link =

    ‘<li’ . $class . ‘>’ .

    ‘ .

    __( ‘Min Profil’ ) .

    ‘ .

    ”;

    $menu = $menu . $author_archive_link;

    return $menu;

    }

    }

    add_filter( ‘wp_nav_menu_items’, ‘my_nav_menu_author_link’ );

    function wpmudev_movemenuitem() {

    if ( is_user_logged_in() ) {

    ?>

    <script type=”text/javascript”>

    jQuery( document ).ready(function($) {

    var last = $(“#menu-meny li”:wink:.last();

    $(last).detach().prependTo(‘#menu-item-127 .sub-menu’:wink:.addClass(‘ion-ios-person-outline’:wink:;

    });

    </script>

    <?

    }

    }

    add_action( ‘wp_footer’, ‘wpmudev_movemenuitem’ );

  • Kasia Swiderska
    • Support nomad

    Hello Robin,

    Your code adds Min Profil to all the menus on the page. Please try this one instead:

    function my_nav_menu_author_link( $items, $args )
    {
    if( !is_user_logged_in() ){

    return $items;

    } else {

    $link = get_author_posts_url( get_current_user_id() );

    $class = is_author() ? ' class="current-menu-item"' : '';

    $author_archive_link =
    '<li' . $class . '>' .
    '<a href="' . $link . '" >' .
    __( 'Min Profil' ) .
    '</a>' .
    '</li>';

    if( $args->theme_location == 'menu-meny' ){
    $items .= $author_archive_link;
    }
    return $items;

    }
    }

    add_filter( 'wp_nav_menu_items', 'my_nav_menu_author_link' );

    Let me know if this will work for you.

    kind regards,

    Kasia

  • Robin
    • WPMU DEV Initiate

    Hi again,

    I’m afraid not – this code doesn’t add any link at all. I tried manipulating it in all ways I could think of but to me it seems the following if-condition doesn’t trigger:

    if( $args->theme_location == ‘menu-meny’ ){

    $items .= $author_archive_link;

    }

    Could you please have a look again? Feel free to use the log in credentials (I share them again in case they were filtered out) so that you can receive direct feedback.

    /// REMOVED CREDS BY STAFF MEMBER

  • Kasia Swiderska
    • Support nomad

    Hello Robin,

    Please change this line:

    if( $args->theme_location == 'menu-meny' ){

    to

    if( $args->theme_location == 'primary' ){

    I mixed the ID of the menu, that one should be correct.

    As for the credentials – I forgot to mention this after the first time I have removed them, but this forum is public so you should never post any credentials here (even if that is a staging site).

    Let me know if the code works now.

    kind regards,

    Kasia

  • Robin
    • WPMU DEV Initiate

    Hi!

    Ok, good to know :slight_smile:

    Unfortunately this didn’t solve the issue either. It seems

    function my_nav_menu_author_link( $items, $args )

    {

    doesn’t add the link at all. It does so with the previous version

    function my_nav_menu_author_link( $menu )

    {

    /Robin

  • Kasia Swiderska
    • Support nomad

    Hello Robin,

    I hesitate to do changes on live site :slight_smile: , I can take look again on staging, but I will need to have FTP access (editing in Editor on site is not safe).

    Note: Don’t leave your login details in this ticket.

    Instead, you can send us your details using our contact form https://premium.wpmudev.org/contact/#i-have-a-different-question and the template below:

    Subject: “Attn: Kasia Swiderska

    – Site login URL

    – FTP credentials (host/username/password) to staging

    – Folder path to site in question

    – Link back to this thread for reference

    – Any other relevant urls/info

    IMPORTANT: Please make sure you select “I have a different question” for your topic, so it doesn’t go back to the forums – this and the subject line ensure that it gets assigned to me.

    Please confirm here that you send those credentials

    kind regards,

    Kasia

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.