A better solution might be to do it along the lines of
/* In your main plugin file */
if ( ! defined( 'YOUR_PLUGIN_ABSPATH' ) ) {
define( 'YOUR_PLUGIN_ABSPATH', dirname( __FILE__ ) );
}
/* In any file of the plugin */
if( is_front_page() ) {
/* adjust path if file.php is in a subfolder */
require_once ( YOUR_PLUGIN_ABSPATH . '/file.php' );
}
If you still have to deal with full paths, they’re in your file.php.
Additional Option
Also, it might not be the best idea to use a conditional tag (if( is_front_page() )
). Alternatively, you could have the plugin generate a shortcode, which outputs the desired markup.
This would have two benefits: For one, it is easily placed and moved within your (front-)page. For another, you can use it anywhere you like, and that without altering code.
/* In your main plugin file */
if ( ! defined( 'YOUR_PLUGIN_ABSPATH' ) ) {
define( 'YOUR_PLUGIN_ABSPATH', dirname( __FILE__ ) );
}
/* In any file of the plugin */
function your_include( $atts ) {
/* "path" is a shortcode attribute, you can use it to include several files */
extract( shortcode_atts(
array(
'path' => 'file.php'
),
$atts ) );
require_once ( YOUR_PLUGIN_ABSPATH . "https://wordpress.stackexchange.com/" . $path );
/**
* file.php should be adjusted to save whatever you were echoing in before
* in a variable (in this example $output), which is returned
* by the shortcode function
*/
return $output
}
add_shortcode( 'your-include', 'your_include' );