I am creating a WordPress plugin and now I want to make an ajax call. For now, I follow this method.
- I create a page through WordPress dashboard
- Create a new Template file
- Put my PHP function in that template file
- Assign that template to my new page.
So My ajax URL is like that http://mywordpresssite/custom_ajax (This basically is a WordPress page but since it has a custom template selected so When I send an ajax request to this I works for me)
Now My question
I am actually tired of creating WordPress page and applying templates. Moreover, my plugins are not plugnplay since I need to create a template in the theme folder. And if accidentally someone deletes that custom_ajax page from the dashboard or trash then my functionality breaks.
Is there a way to create a page (or link) through my plugin and then I put my custom function in it so If someone goes to that link it actually accessing my custom function(like Code Igniter does it). My question is not specifically about Ajax, I know WordPress has another way to deal with ajax but I only want to know that Is it possible to create a page or link through a plugin and point it to a custom function of the plugin.