I'm trying to use a file for my Twitter sign in authentication callback that isn't in the traditional WordPress template hierarchy.

This is a problem I generally want to solve away from this one instance.

How do you use a file within a template for things like login authentication without receiving a 404?

Current file setup:

define('WP_USE_THEMES', false);

// oauth.php. Your callback File

if ( isset($_GET['oauth_token']) ) {

    // ---------- CODE

    // redirect to main page
    header('Location: front-page.php');

    // ---------- CODE
  • If you are trying to use a template file, why do you use define('WP_USE_THEMES', false);? Is your script directly executed or is it executed in WordPress context?
    – cybmeta
    Mar 13, 2015 at 10:07
  • @cybmeta I worded it wrong, apologies. It's a none template file and it's to be executed directly, redirecting the user back to the homepage Mar 13, 2015 at 10:13
  • I think is possible that you get the 404 Not found error because of the wrong use of header('Location: front-page.php');. The location must be a URL. Try header( 'Location: ' . esc_url_raw( get_home_url() ) ); or similar.
    – cybmeta
    Mar 13, 2015 at 10:16
  • @cybmeta I'm now getting an 'internal server error'. I've stripped the file back to just define('WP_USE_THEMES', false); header( 'Location: ' . esc_url_raw( get_home_url() ) ); exit; Mar 13, 2015 at 10:33
  • The issue before was that I didn't just .php at the end of the callback URL...school boy error :) Mar 13, 2015 at 10:34


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.