0

I want to use printf to print this:

Login or register to be able to add new adverts

I need to print two links, one for login and one for registration. i know how to print one but i don't know how i can add second in the same text.

Please if somebody knows, help me :D

apply_filters("adverts_action_$action", $content, $form);
    function wpjb_check_user_logged_in() {
    if ( is_user_logged_in() ) {
        $current_user = wp_get_current_user();
       ( 'Non-Personalized Message!' );
    } else {

         $text = __('<strong><a href="%2$s">login</a> or <a href="%2$s">register</a>register to be able to add new adverts</strong>', 'adverts');
        printf( '<div>'.$text.'</div>', wp_get_current_user(), wp_login_url());
    }
}
add_action( 'adverts_action', 'wpjb_check_user_logged_in' );

1 Answer 1

1

This should do it:

$text = __( '<strong><a href="%1$s">login</a> or <a href="%2$s">register</a> to be able to add new adverts</strong>', 'adverts' );
printf( '<div>' . $text . '</div>', wp_login_url(), wp_registration_url());
2
  • Thanks! And how it will look if i want use "sprintf" ? Commented Jun 1, 2017 at 7:42
  • @Proctosone sprintf is the same as printf, but it does not print the string, just returns it, so you need echo too in order to print it Commented Jun 1, 2017 at 7:50

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.