I’m trying to use plugins to abstract custom features from the theme design and site content, and I’ve run into a roadblock.
One such feature is a Location Picker. Here’s how it’s currently implemented:
- A “show-selected-location” function is called from header.php
- A “show-selected-location” action is added in functions.php, with the appropriate code to display the location data from a cookie, along with a link to a page where the user can change their location.
- The link currently points to a WP Page, which is assigned a custom page template named “location-picker.php”
After making it work in the theme, I’m now trying to put the functionality into a plugin. I’ve got everything working great so far—the current location and link are showing up correctly—but I can’t seem to figure out the Location Picker page, which I’m trying to move out of the database and into a static file in the plugin. I put the code from “location-picker.php” into a php file within the plugin folder, and I am able to link to the page and display plain HTML; however, I can’t use any WP functions such as get_terms() or get_header() or anything.
Should I be using a different approach? I really like the idea of keeping the dynamic functionality out of the theme and having it self-contained in a plugin. I could include the location picker code in a hidden div and use a lightbox to display it, but I want to avoid including the get_terms() query on every page.
I feel like I’m missing something really basic, but it’s hard to tell—this is a tough problem to google…
- The topic ‘Using a plugin to add a static PHP page’ is closed to new replies.