i am writing a wordpress plugin.
In order to decrease page load time i decided to go with AJAX.So what i mean is when the page loads an ajax must be triggered and the content must be loaded by a request.
My question is that i am not writing a theme,so how can i do this with a plugin?
i am writing a wordpress plugin. In order to decrease page load time i
Share
You can use the wp_enqueue_script to load your js into the page and do the ajax request from that js file. Here we are using wp_head hook to place it into the
<head>section of your theme.Also if you are developing a custom theme then be sure to have
<?php wp_head(); ?>before closing you</head>tag in your header.phpPS: I’m assuming you are using jQuery for you ajax requests so I included that library in the code as prerequisite, so WordPress will include that library before your js file.