0

I have theme with this code in one php file :

'logged_in_as' => '<p class="logged-in-as">'.
                    sprintf( __( 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>', 'testshop' ),
                    admin_url( 'profile.php' ),
                    $user_identity,
                    wp_logout_url( apply_filters( 'the_permalink', get_permalink( ) ) ) ).
                  '</p>',

Now I want to change this code and unlocalized and only one text.

I change this to code below , but not work and get the error

Parse error: syntax error, unexpected 'echo' (T_ECHO)

'logged_in_as' => '<p class="logged-in-as">'.
                    echo ( 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>'),
                    admin_url( 'profile.php' ),
                    $user_identity,
                    wp_logout_url( apply_filters( 'the_permalink', get_permalink( ) ) ) ).
                  '</p>',

please help me to fix this. thanks

1 Answer 1

1

The main problem is that you removed the sprintf.

Replace the echo with sprintf and remove the ().

Should be like this

'logged_in_as' => '<p class="logged-in-as">'.
                    sprintf( 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>',
                    admin_url( 'profile.php' ),
                    $user_identity,
                    wp_logout_url( apply_filters( 'the_permalink', get_permalink( ) ) ) ).
                  '</p>',

Be careful! changing code directly in a plugin will lead to problems.

Next plugin update your code will be removed so be mindful.

If you can try using a filter, if the plugin has one. That way the changed you are doing when connecting to that filter will stay, unless the plugin author changed the filter name =]

5
  • Thanks and what change this code need? ----> : <p class="message"><?php echo sprintf(_n('You have 1 item in your shopping cart','You have %d items in your shopping cart', $woocommerce->cart->cart_contents_count, 'testshop'), $woocommerce->cart->cart_contents_count);?></p>
    – masoud nkh
    Commented Apr 28, 2021 at 13:50
  • What do you mean what change? also removing localization? Commented Apr 28, 2021 at 13:51
  • With this change , i want to develope custom theme and only for one language (not need to localization ).
    – masoud nkh
    Commented Apr 28, 2021 at 13:54
  • Going by the functionality of _n I would do something like this. sprintf(($woocommerce->cart->cart_contents_count == 1 ? 'You have 1 item in your shopping cart' : 'You have %d items in your shopping cart'), $woocommerce->cart->cart_contents_count); Commented Apr 28, 2021 at 13:58
  • Thank you very much. You helped me a lot
    – masoud nkh
    Commented Apr 28, 2021 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.