0

I have added custom PHP file in WordPress directory and added following line to use WordPress functions:

require ('../wp-blog-header.php');

Now I am able to use WordPress functions but unable call this file from javascript in ajax.

When I removed following line then I am able to call this file:

require ('../wp-blog-header.php');

Please suggest how can I solve this issue.

4
  • do you receive any errors while require string is present? Commented Nov 6, 2017 at 14:58
  • do you mean you put it directly in wp-admin, wp-content or wp-includes? If so, this is not really safe, because your file could be deleted on Wordpress update. It should be either in your template, or maybe outside of wordpress directory if there is one Commented Nov 6, 2017 at 15:06
  • @RafailAkhmetshin I am getting 404 (Not Found) error Commented Nov 6, 2017 at 15:33
  • @Kaddath thank you for advice. But still, I won't be able to access PHP file as I have added wp-blog-header.php file. Commented Nov 6, 2017 at 15:34

1 Answer 1

2

looks like this is standard behavior of WP

change

require ('../wp-blog-header.php');

to this line

require(dirname(__FILE__) . '../../wp-config.php'); //path to Your wp-config.php file

$wp->init();
$wp->parse_request();
$wp->query_posts();
$wp->register_globals();
//$wp->send_headers();
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.