Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Path to WordPress function using a script.js file

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #33915
    fjorko
    Member

    I have embedded in my head tag -> Jquery and my custom.js file. It works.

    Now – how do one reference a wordpress function in my custom.js file in order for a path to be recognised by wordpress – example:

    $(“#div”).load(“/loadme.php”);

    I know it is client-side code and that Javascript cannot interpret that path ( as it needs to be parsed by PHP on the server side )…but that being the case…what is the correct way to do this sort of thing in your own custom wordpress pages ?

    Thanks

    #85019
    SgtLegend
    Member

    The quickest way i can think of is to add a new action to your functions.php file in your current themes folder so you can reference the template directory var.

    add_action('wp_head', function() {
    echo '';
    });

    Then in your custom JS file you can simply reference template_dir

    $("#div").load(template_dir + "/loadme.php");
    #85020
    fjorko
    Member

    Ok, thanks – I’ll try that !

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.