SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    May 2007
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Plugin won't work in child theme

    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 Code:
    <?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');

    ?>

  2. #2
    SitePoint Enthusiast
    Join Date
    Feb 2012
    Location
    New Delhi
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  3. #3
    SitePoint Zealot
    Join Date
    May 2007
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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 Code:
    <?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');

    ?>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •