I using below code for showing error message to users in my WordPress website

if ( $wp_error ) {
    return new WP_Error( 'you_cannot_vote_on_restricted', __( 'Voting on restricted posts are not allowed.', 'anspress-question-answer' ) );

Now I want show error message to users with hyperlink. I use below code to do that, But this code showing just text

    if ( $wp_error ) {
return new WP_Error('no_permission', sprintf(__('<strong>ERROR</strong>: Invalid username. <a href="%s" title="Password Lost and Found">Lost your password</a>'), site_url('wp-login.php?action=lostpassword', 'login')));

enter image description here

This is my error message

How can I show error message to user with hyperlink?

  • How are you displaying the error message?
    – Tom J Nowell
    Commented Oct 29, 2020 at 20:47
  • I use a plugin, this plugin use WP_Error class for showing message. WP_Error is a class that makes error handling within plugins and WordPress.
    – mohammad
    Commented Oct 29, 2020 at 22:02
  • I know what WP_Error is, but how that error object is displayed is super important. If that plugin applies escaping to the message on output then your answer is likely a hard no. Either way i cannot determine this as you've neither shared the code or identified the plugin, it isn't even clear where the code your posted is located or how it's called as there's very little context provided
    – Tom J Nowell
    Commented Oct 30, 2020 at 1:01


Your Answer

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

Browse other questions tagged or ask your own question.