• Resolved ianpullens

    (@ianpullens)


    I love this plugin and it mostly works great. I’m using it to build a custom login button with a returnURL.

    But it stops working on my 404 page. I’m assuming this page is not registering shortcodes.

    Any ideas on how to get this working?

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Gagan Deep Singh

    (@gagan0123)

    @ianpullens

    Thanks for reporting the issue ??

    Would be happy to help you out.

    Can you share the code of the function that is generating the shortcode?

    I tested on dev site I have, and there, even on 404, any shortcode registered in functions.php or via third party plugins, are working as expected and output is exactly the same. So I think there’s something in that particular function thats failing on 404 page, and will need to be debugged.

    Thread Starter ianpullens

    (@ianpullens)

    sure. I’m glad you’ve found that it’s working. So I’m sorry that it may be my configuration. here is that code for that shortcode:

    // Add shortcode for login link with return URL
    function setup_loginreturn() {
        //only add permalink if not 404
        if (strpos ($_SERVER ['REQUEST_URI'] , '404' )){
        	$return_url = '';
        } else { $return_url = get_permalink(); }
        
        return wp_login_url($return_url);
    }
    add_shortcode( 'loginreturn', 'setup_loginreturn' );
    

    but even without the 404 condition in there, when the function was simply
    return wp_login_url();

    It still didn’t work.

    • This reply was modified 5 years, 11 months ago by ianpullens.
    • This reply was modified 5 years, 11 months ago by ianpullens.
    Plugin Author Gagan Deep Singh

    (@gagan0123)

    @ianpullens

    I tested out this code, it turns out what you’ve provided here, works just fine, but instead of testing for 404 on your own, you can make use of WordPress function is_404()

    I tried this code as well, and even this works:

    
    // Add shortcode for login link with return URL
    function setup_loginreturn() {
        //only add permalink if not 404
        if ( is_404() ){
            $return_url = '';
        } else { $return_url = get_permalink(); }
    
        return wp_login_url($return_url);
    }
    add_shortcode( 'loginreturn', 'setup_loginreturn' );
    
    • This reply was modified 5 years, 11 months ago by Gagan Deep Singh. Reason: Changed code quote
    Thread Starter ianpullens

    (@ianpullens)

    Thanks for the tip on is_404()

    Yeah I did more testing and your plugin is indeed working fine. For some reason it’s wp_login_url() specifically that does not want to load on 404. No idea why.

    I ended up doing it in a less procedural way and it gets the job done.

    // Add shortcode for login link with return URL
    function setup_loginreturn() {
        //only add permalink if not 404
        if ( is_404() ){return '/login';
            
        } else {  return wp_login_url(get_permalink()); }  
    }
    add_shortcode( 'loginreturn', 'setup_loginreturn' );
    Plugin Author Gagan Deep Singh

    (@gagan0123)

    @ianpullens

    Good to know you got it working ??

    I simply assume that either wp-includes/general-template.php is not being included for some reason, which would cause an error and don’t return the login URL properly, or there’s some plugin or code overriding the login URL with login_url filter, returning blank on 404 pages on your setup.

    Wish I could be of more help figuring out what exactly is causing this.

    Marking this issue as resolved, you can provide more feedback on this topic, if you find anything in the error log not making sense, I’d be happy to help ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘stops working on 404 page’ is closed to new replies.