• Hello. I have put an ajax query in the functions.php file like this.

    add_action(‘wp_footer’, ‘my_ajax_code’);
    function my_ajax_code() {
    ?>
    <script type=”text/javascript”>
    function login(){
    alert(“fgffg”);
    var emailaddress = document.getElementById(“emailaddresstext”).value;
    var password = document.getElementById(“passwordtext”).value;

    $.ajax({
    type: “POST”,
    url: “https://www.mysite.ca/wordpress/wp-admin/login.php&#8221;,
    data: “emailaddress=”+emailaddress+”&password=”+password,
    success: function(html){

    alert(“working “+html);

    if(html==’true’) {
    $(“#add_err”).html(“Right email address or password”);

    }
    else {
    $(“#add_err”).css(‘display’, ‘inline’, ‘important’);
    $(“#add_err”).html(“<img src=’images/alert.png’ />Wrong email address or password”);
    }
    },
    beforeSend:function()
    {
    $(“#add_err”).css(‘display’, ‘inline’, ‘important’);
    $(“#add_err”).html(“<img src=’images/ajax-loader.gif’ /> Loading…”)
    }
    });

    return false;

    }
    add_action( ‘wp_enqueue_scripts’, ‘login’ );

    </script>
    <?php
    }

    I was taught to do this by someone. I was using

    jQuery(document).ready(function($) {

    });
    It wasn’t working in the footer.php file, so I put my code in the functions.php file and now it works. But now if i want to use my login(){} function anywhere on my site it doesnt work. How do i make that js function work on the rest of my site? thanks

Viewing 1 replies (of 1 total)
  • Thread Starter johnboyman

    (@johnboyman)

    i think i should say my question again how do i put javascript functions in the functions.php file and have then accessable on all of my pages thanks.

Viewing 1 replies (of 1 total)
  • The topic ‘how to add js functions to functions.php’ is closed to new replies.