1

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??

2

In your main plugin file just define a constant containing the path of the plugin:

$pluginpath = plugin_dir_path( __FILE__ );
define('MY_AWESOME_PLUGIN_PATH', $pluginpath);

After that in your header.php:

include(MY_AWESOME_PLUGIN_PATH . 'html_file_name.html');
2

Check out WP's plugins_url function

<?php
 echo '<img src="' . plugins_url( 'images/wordpress.png' , __FILE__ ) . '" > ';
 ?>

check out more on the Wordpress Codex

0

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

<?php
function my_output() {
    $html = 'This is some HTML that should go in the header.';
    echo( $html );
}

themes/my_theme/header.php

.
.
.
if( function_exists( 'my_output' ) ) {
    my_output();
}
.
.
.
0

You can include your files

include '../plugins/my_plugin//plugin.php';

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.