PHP called by Ajax in a page template cannot use WordPress functions

I have a page template in WordPress that calls an ajax function. That ajax calls an php function in another file, all declared like mentioned in ajax api in WordPress. Then I want to use in that php function a WordPress function, like get_template_dir_url() and that call throw me an error that the function get_template_dir_url() is not declared.

I had tried to load wp-load() and other methods but they throws “already defined” errors. Your help with this would be very appreciated. Thanks in advance.

Related posts

Leave a Reply

1 comment

  1. You can use the function get_template_directory_uri(), the problem is because you have a typo with the last character.

    <?php
    if ( !isset($wp_did_header) ) {
    
        require_once( dirname(__FILE__) . '/wp-load.php' );
    
        echo get_template_directory_uri();
    }