Show buttons in header only on specifc pages

Hello.
I have added the below code to our x-child functions.php
I want that this button is only shown on two specifc pages (currently it is shown on all pages in German).
How can I achieve that?
Thank you a lot in advanve.

function my_navigation_buttons( $items, $args ) {

if (ICL_LANGUAGE_CODE == ‘de’) {

  if ( $args->theme_location == 'primary' ) {
    $items .= '<li class="menu-item right login-btn">'
              . '<a href="/xxx.html"><span>'
                . 'Sign-Up'
              . '</span></a>'
            . '</li>'
            . '<li class="menu-item right sign-up-btn">'
              . '<a href="/yyyy.html?cms[loginscreen]=1"><span>'
                . 'Login'
              . '</span></a>'
            . '</li>';
  }
return $items;

}

Hi @jorgeHX

Thanks for reaching out.
You need to add another condition to check the specific page ids inside the existing condition.

function my_navigation_buttons( $items, $args ) 
{
    if (ICL_LANGUAGE_CODE == ‘de’) 
    {
        if ( $args->theme_location == 'primary' ) 
        {
            if(is_page(array(pageid1,pageid2)))// change page id with your page ids 
            { 
                $items .= '<li class="menu-item right login-btn">'
                        . '<a href="/xxx.html"><span>'
                            . 'Sign-Up'
                        . '</span></a>'
                        . '</li>'
                        . '<li class="menu-item right sign-up-btn">'
                        . '<a href="/yyyy.html?cms[loginscreen]=1"><span>'
                            . 'Login'
                        . '</span></a>'
                        . '</li>';
            }
        }
        return $items;
    }
}

If you are not able to find the page ids, please go through this article where it has been described: https://theme.co/docs/how-to-locate-post-ids.
You can also use the Page Title instead of id in the same way ids are used like: is_page(array('page title1','page title2')).

Hope it helps.
Thanks

Works perfectly. THX

Hi @jorgeHX,

You’re welcome and it’s our pleasure to help you. If you have any other concerns, feel free to reach us.

Thank you.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.