Title: WordPress plugin structure – 404 replacement feature
Last modified: October 25, 2019

---

# WordPress plugin structure – 404 replacement feature

 *  [lpenn](https://wordpress.org/support/users/lpenn/)
 * (@lpenn)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/wordpress-plugin-structure-404-replacement-feature/)
 * I need to create a custom WordPress plugin that “talks” with a separate PHP application.
   When the user types a URL that does not exist on WordPress, I want WordPress 
   to check whether my other PHP app has some HTML content to render (if yes, then
   render it) before WordPress throws a 404 error.
 * Here is the current file structure:
 *     ```
       mysite.com -> a basic WordPress site
       mysite.com/app -> a complex php app (PHP, MySQL, CodeIgniter)
       ```
   
 * When the user visits a page that does not exist on my WordPress, i.e:
 * `mysite.com/user.profile/`
 * I want WordPress to run a function (before the 404 error) that checks whether
   the app has some valid html data to render in that specific page. If the app 
   responds with some HTML, render it, if not, display the 404 error.
 * QUESTIONS:
 * 1) How can I accomplish this with a custom WordPress plugin? (hooks, filters,
   etc that I should keep into consideration? – I’m not a WordPress plugin expert)
 * 2) Should I write an API or use a dirty PHP include to let 2 systems talk to 
   each other? (they’re on the same server as shown in the file structure)
 * 3) Sitemap: this is a tricky question for developers. Do you think that it would
   be easier to generate a separate sitemap (for those pages only) via the /app 
   or via WordPress?

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/wordpress-plugin-structure-404-replacement-feature/#post-12066509)
 * You can use the “template_include” filter to see if WP wants to use a 404 template
   and do supplemental checks before giving up. Whatever path your callback returns
   will be immediately `include`d, so you can hand off execution to another app’s
   PHP file here, or go to a custom interface script that in turn queries the other
   app.
 * Any WP plugin that dynamically serves sitemaps is only going to list WP resources.
   Some such plugins provide hooks where you can add in your own links in addition
   to whatever the plugin does. The specifics and availability depend on which plugin
   you use.
 *  [crslz](https://wordpress.org/support/users/crslz/)
 * (@crslz)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/wordpress-plugin-structure-404-replacement-feature/#post-12068712)
 * [Intercept 404 Errors In WordPress](https://paulund.co.uk/how-to-intercept-404-errors-in-wordpress)

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘WordPress plugin structure – 404 replacement feature’ is closed to new
replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 3 participants
 * Last reply from: [crslz](https://wordpress.org/support/users/crslz/)
 * Last activity: [6 years, 7 months ago](https://wordpress.org/support/topic/wordpress-plugin-structure-404-replacement-feature/#post-12068712)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
