I am using an includes plugin that works fine for all theme except a child them. In a child theme it looks for the included file in the parent theme.
How can I set the theme root so it recognizes the child and not the parent?
<?php
/*
Plugin Name: PHP File Includer
Description: Include PHP files using a shortcode
Version: 1.0
*/
// include PHP file
// usage = [phpinclude file='myfilename']
function PHP_Include($params = array()) {
extract(shortcode_atts(array(
'file' => 'default'
), $params));
ob_start();
include(get_theme_root() . '/' . get_template() . "/inc/$file.php");
return ob_get_clean();
}
// register shortcode
add_shortcode('phpinclude', 'PHP_Include');
?>
Thats the problem while developing a child theme. I always choose codes from a free theme makers to make a child theme so that I can get the updated code in future for the same and also it also helps in supporting the plugins.
My question had nothing to do with pre-made themes. It’s about modifying a plugin that will work with child themes, pre-made or custom.
I found my answer, which is posted below.
<?php
/*
Plugin Name: PHP File Includer
Description: Include PHP files using a shortcode
Version: 1.0
For using the plugin with a child theme
http://codex.wordpress.org/Function_Reference/get_stylesheet_directory
For normal usage, use this query
include(get_theme_root() . '/' . get_template() . "/inc/$file.php");
*/
// include PHP file
// usage = [phpinclude file='myfilename']
function PHP_Include($params = array()) {
extract(shortcode_atts(array(
'file' => 'default'
), $params));
ob_start();
// get file from child theme
include(get_stylesheet_directory() . "/inc/$file.php");
return ob_get_clean();
}
// register shortcode
add_shortcode('phpinclude', 'PHP_Include');
?>