2

MY website is in wordpress. I have file api.php that is placed in same folder as index.html But when i do mysite.com/api.php it redirects to wordpress page that no page is found.

Is there a way to access custom php file (e.g api.php) through url ?

3
  • it's not recommanded to use a direct acces to a PHP file. it's better to use instead AJAX (codex.wordpress.org/AJAX_in_Plugins) or REST (developer.wordpress.org/rest-api) Commented Feb 6, 2018 at 10:05
  • there are special URL rewriting rules in Wordpress for you to be able to access your site via mysite.com/anyContentUrl through index.html. But if you want to access to a custom file, you have to precise the full URL, for example for your theme mysite.com/wp-content/themes/yourTheme/file.php. If you don't want this path to be shown, place it in another folder in your site root for example (and still access it with its full URL) Commented Feb 6, 2018 at 10:06
  • Please check this wordpress.stackexchange.com/questions/39765/… which is similar to your problem. Commented Feb 6, 2018 at 10:26

3 Answers 3

2

Place your file to root of wordpress directory,where wp-config file exist. Clear cache and try to access your file via url.

Sign up to request clarification or add additional context in comments.

Comments

1

Place your file(api.php) to root of wordpress directory,where wp-config.php file exist.

Clear cache and try to access your file via url.

Comments

0
Create folder at your website root directory
like:
wp-admin
wp-content
wp-yourfolder/yourfile.php,
than in yourfile.php include

include('wp-config.php');
and do what you want like

$wpdb->get_results( "SELECT post_date, ID  FROM $wpdb->posts  WHERE post_status = 'publish' ");

3 Comments

Its not even letting me access subfolder.(wp-yourfolder)
@user3603023 do you have a plugin to protect some folders access? or a plugin for security more generally?
Refer to this toturial: wpbeginner.com/wp-tutorials/…

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.