开发者

Insert a wordpress page with a function/plugin

I am creating a WordPress plugin and now I want to make an ajax call. For now, I follow this method.

  1. I create a page through WordPress dashboard
  2. Create a new Template file
  3. Put my PHP function in that template file
  4. 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 ac开发者_运维百科cessing 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.


Perhaps I am missing something, but this seems like a really strange way to do things. How come you can't just add your function to a file in your plugin directory and call it when you want to use it? Use plugin_basename whenever you want to call it.

http://codex.wordpress.org/Function_Reference/plugin_basename

So send your ajax call to plugin_basename(__FILE__)

UPDATE I think you need to provide more information about what exactly on the page you need to modify, but you can use wordpress hooks to add or modify content on a page. So for example you can insert code into the head of your page (css or js links, etc) by adding the following line to your plugin.

add_action('wp_head', 'your_function');

There are a whole bunch of these defined in the Wordpress Codex

You can also create your own shortcodes that could reference a file in your plugin directory.

http://codex.wordpress.org/Shortcode_API

You could then include the code in your pages by including the shortcode.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜