I know that plugins and theme files should be kept separate but for for internal use I need to do it this way.
In my themes header.php file I want to include a php file which just contains html, from my plugin directory.
The path is basically /wp-content/plugins/my_plugin/my-html.php
I can’t seem to figure out the proper code for wordpress to look in the plugins directory, and grab the my-html.php file from within the my_plugin folder. I want to include this file so the html in it is included in the header.php within my theme.
What would be the best way to go about this??
In your main plugin file just define a constant containing the path of the plugin:
After that in your
header.php
:Check out WP’s plugins_url function
check out more on the WordPress Codex
If the
plugins/my_plugin/my-html.php
file is only going to output HTML, you could do it like this:plugins/my_plugin/my-html.php
themes/my_theme/header.php
You can include your files using
if the header of your plugin is in the right folder. .. goes back one folder to the wp-content, then u go to plugins/yourpluginfolder/phpfile.
As I stated in my comment I think what you’re looking for, as it’s basically just adding HTML from a plugin into a theme, is a template tag.
So in either your main plugin file, or a separate file you’ll want to do something like this:
Then, in the template where you want this to show up, which is your header.php, you want to place the template tag we created for the plugin right where you want it’s HTML to appear.
If you made this a separate file you’ll want to require the file in your main plugin file like so:
include( plugin_dir_path( __FILE__ ) . 'yourplugin_templatetag.php' );
Of course name the file what you like, as well as the template tag, and if the files in an includes directory or whatever, make sure you include that in the path.