简体   繁体   中英

How to add php pages with ajax request to another php in wordpress?

I have two php files- index.php ajax.php

The index.php file contains html, javascript and css along with bootstrap and jquery library.

These are my previous website pages, which are stand-alone, single page website.

How can I add these to a wordpress site so that when the user visits a link, it shows content of index.php and from index.php, the jquery search to ajax.php is performed?

I tried making custom templates and created a page with it, but it does not search for ajax.php file for the ajax requests.

How can I do it? I am a developer myself, I understand PHP, but not the wordpress cms.

There are two approaches. You can either change index.php to another file, say, "search.php", and it will co-exist with Wordpress and everything will work.

Or, you can "transplant" your index.php into the Wordpress eco-system:

  1. create a "page" in wordpress so that you'll have a container.
  2. in "functions.php", create a custom shortcode with the add_shortcode function. (you could create a plugin as part of the theme so that when you upgrade Wordpress your changes stay compatible, but for now you can just change functions.php)
  3. in the content of the new page, use the shortcode.

You can move the jQuery code, HTML markups, etc. into the definition of the shortcode. You might run into some styling collisions but for the most part it should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM