• Resolved sasikumar3g

    (@sasikumar3g)


    Hi,

    Thank you for the plugin. It’s working perfect in my site,

    However, I want to redirect or show 404 error when someone directly enter wp-admin. instead of showing the message “You must log in to access the admin area.”

    Is it possible to do ? I tried with url redirect plugins but it’s not working.

    • This topic was modified 4 years, 8 months ago by sasikumar3g.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Hi @sasikumar3g

    Thank you for using my plugin.

    You don’t want to redirect wp-admin to 404 otherwise how would you log in or user wp-admin backend?

    What is 404 page:
    “The HTTP 404, 404 Not Found, 404, Page Not Found, or Server Not Found error message is a Hypertext Transfer Protocol (HTTP) standard response code, in computer network communications, to indicate that the browser was able to communicate with a given server, but the server could not find what was requested.”

    First, you need to check if the user is logged in and if not redirect the user to a different page.

    Code starting point (not tested):

    add_action( 'admin_init', 'redirect_non_logged_users_to_specific_page' );
    
    function redirect_non_logged_users_to_specific_page() {
    
    if ( !is_user_logged_in() && is_page('add page slug or ID here') && $_SERVER['PHP_SELF'] != '/wp-admin/admin-ajax.php' ) {
    
    wp_redirect( 'https://www.example.dev/page/' ); 
        exit;
       }
    }
    • This reply was modified 4 years, 7 months ago by Nuno Sarmento.

    I am closing this ticket for now but if you need any more help please let me know.

    @sasikumar3g
    WPS Hide Login by WPServeur, NicolasKulka, tabrisrp
    allows you to set redirect URL for anoymous attempts.

    Would be nice to see same feature in this plugin.

    Reading the plugin code, I solved redirecting to home, but would be good if that is native plugin code, please reconsider implement a option to redirect where you would like:

    add_action( 'wp_loaded', 'redirect_to_home', 9);
    
    function redirect_to_home() {
    
    	if ( is_admin() && ! is_user_logged_in() && ! defined( 'DOING_AJAX' ) ) {
    
    		wp_redirect( get_site_url() ); 
    	    exit;
        }	
    }

    PS .:Thank you for this plugin, I had some issues with WPS Hide Login, so I found this. Hope that I will keep with this solution for life.

    • This reply was modified 4 years, 6 months ago by lvfxbr.
    • This reply was modified 4 years, 6 months ago by lvfxbr.

    @lvfxbr

    Thank you for that.
    Your code is no that different from the one I gave it to @sasikumar3g. Unfortunately from the 10.000 plus active installations I only have your request to add this functionality, if I had more people asking for this “redirect” I would have done it already – anyway I will keep your idea on the “to do” plugin list.

    Best,
    Nuno

    anonymized-14293447

    (@anonymized-14293447)

    …let me just jump in by saying that if one has got the 404 page set correctly, the redirect is automatically done. Mine does, and it’s a confirmation that this plugin is well coded. ??

    Thank you @arsenalemusica for using my plugin, I’m glad you like it. If the theme follows WordPress standards, yes, that correct, it should redirect to a 404 page.

    Thank you,
    Nuno

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to redirect wp-admin page after changing the admin url’ is closed to new replies.