• Hi,

    I am trying to modify my child theme. Right now the function.php has got the following code:

    require_once( get_template_directory() . '/admin/main/options/02.homepage.php' );

    I have edited the 02.homepage.php and saved it under the same directory structure in my child theme. If I change the function.php code in the parent theme to

    require_once( get_template_directory() . '/../child_theme/admin/main/options/02.homepage.php' );

    it works fine. But if I write the same code in my child theme function.php it doesn’t work. If I write get_stylesheet_directory the site goes blank.

    I read somewhere that if the code doesn’t have

    if ( ! function_exists…

    before, then you can’t overwrite the parent function in your child theme.

    Any ideas? Appriciate the help!

Viewing 15 replies - 1 through 15 (of 17 total)
  • Tim Nash

    (@tnash)

    Spam hunter

    You were right to use get_stylesheet_directory
    to find the child theme.
    http://codex.wordpress.org/Function_Reference/get_stylesheet_directory

    If it was blank, then in your child theme try var_dump(get_stylesheet_directory())
    which will dump out the path and check it’s correct assuming it is then it should just be
    require_once( get_stylesheet_directory() . '/admin/main/options/02.homepage.php' );
    Make sure in your child theme the folders are setup the same.

    Thread Starter raggie

    (@raggie)

    Thank you for your answer!

    When I do that the path points to the Child theme folder. Any idea how can i get it to Point to the folders under the Child theme ('/admin/main/options/') ?

    Tim Nash

    (@tnash)

    Spam hunter

    require_once( get_stylesheet_directory() . '/admin/main/options/02.homepage.php' );
    will load the specific file or if you prefer

    $options_path = get_stylesheet_directory() . '/admin/main/options/';

    Will set the variable with the path to the options folder.

    Thread Starter raggie

    (@raggie)

    Still isn’t working. Just getting the blank page. It has to be something else wrong?

    Tim Nash

    (@tnash)

    Spam hunter

    can you post the code you have just tried?

    Thread Starter raggie

    (@raggie)

    I tried

    <?php
    require_once( get_stylesheet_directory() . '/admin/main/options/02.homepage.php' );
    ?>

    and

    <?php
    require_once( get_stylesheet_directory() . '/admin/main/options/02.homepage.php' );
    $options_path = get_stylesheet_directory() . '/admin/main/options/';
    ?>
    Tim Nash

    (@tnash)

    Spam hunter

    Where are you adding this code?
    Which file in which folder?

    Thread Starter raggie

    (@raggie)

    in functions.php in the root folder of my Child theme.
    Same Place as the parent theme.

    Tim Nash

    (@tnash)

    Spam hunter

    Can you post your entire functions file?

    Thread Starter raggie

    (@raggie)

    in my child theme, that’s all. But the following code is in the parent function.php:

    <?php
    
    // Setup content width 
    
    if ( ! isset( $content_width ) )
    
    	$content_width = 960;
    
    /* ----------------------------------------------------------------------------------
    
    	Add Theme Options Panel & Assign Variable Values
    
    ---------------------------------------------------------------------------------- */
    
    	// Add Redux Framework - Credits attributable to http://reduxframework.com/
    
    	require_once (get_template_directory() . '/admin/main/framework.php');
    
    	// Add Theme Options Features.
    
    	require_once( get_template_directory() . '/admin/main/options/00.theme-setup.php' ); 
    
    	require_once( get_template_directory() . '/admin/main/options/00.variables.php' ); 
    
    	require_once( get_template_directory() . '/admin/main/options/01.general-settings.php' ); 
    
    	require_once( get_template_directory() . '/admin/main/options/02.homepage.php' ); 
    
    	require_once( get_template_directory() . '/admin/main/options/03.header.php' ); 
    
    	require_once( get_template_directory() . '/admin/main/options/04.footer.php' );
    
    	require_once( get_template_directory() . '/admin/main/options/05.blog.php' ); 
    
    	require_once( get_template_directory() . '/admin/main/options/06.portfolio.php' ); 
    
    	require_once( get_template_directory() . '/admin/main/options/07.contact-page.php' ); 
    
    	require_once( get_template_directory() . '/admin/main/options/08.special-pages.php' ); 
    
    	require_once( get_template_directory() . '/admin/main/options/09.notification-bar.php' ); 
    
    	require_once( get_template_directory() . '/admin/main/options/10.seo.php' ); 
    
    	require_once( get_template_directory() . '/admin/main/options/11.typography.php' ); 
    
    	require_once( get_template_directory() . '/admin/main/options/12.custom-styling.php' );
    
    	// Add widget features.
    
    	include_once( get_template_directory() . '/lib/widgets/categories.php' ); 
    
    	include_once( get_template_directory() . '/lib/widgets/popularposts.php' ); 
    
    	include_once( get_template_directory() . '/lib/widgets/recentcomments.php' ); 
    
    	include_once( get_template_directory() . '/lib/widgets/recentposts.php' ); 
    
    	include_once( get_template_directory() . '/lib/widgets/searchfield.php' ); 
    
    	include_once( get_template_directory() . '/lib/widgets/tagscloud.php' );
    
    /* ----------------------------------------------------------------------------------
    
    	Assign Theme Specific Functions
    
    ---------------------------------------------------------------------------------- */
    
    /* Setup theme features, register menus and scripts.  */
    
    if ( ! function_exists( 'thinkup_themesetup' ) ) {
    
    	function thinkup_themesetup() {
    
    		/* Load required files */
    
    		require_once ( get_template_directory() . '/lib/functions/extras.php' );
    
    		require_once ( get_template_directory() . '/lib/functions/template-tags.php' );
    
    		/* Make theme translation ready. */
    
    		load_theme_textdomain( 'lan-thinkupthemes', get_template_directory() . '/languages' );
    
    		/* Add default theme functions. */
    
    		add_theme_support( 'automatic-feed-links' );
    
    		add_theme_support( 'post-thumbnails' );
    
    		add_theme_support( 'custom-background' );
    
    		// Add support for custom header
    
    		$args = apply_filters( 'custom-header', array( 'height' => 200, 'width'  => 1600 ) );
    
    		add_theme_support( 'custom-header', $args );
    
    		/* Register theme menu's. */
    
    		register_nav_menus( array( 'pre_header_menu' => 'Pre Header Menu', ) );
    
    		register_nav_menus( array( 'header_menu' => 'Primary Header Menu', ) );
    
    		register_nav_menus( array( 'sub_footer_menu' => 'Footer Menu', ) );
    
    	}
    
    }
    
    add_action( 'after_setup_theme', 'thinkup_themesetup' );
    
    /* ----------------------------------------------------------------------------------
    
    	Register Front-End Styles And Scripts
    
    ---------------------------------------------------------------------------------- */
    
    function thinkup_frontscripts() {
    
    	/* Add jQuery library. */
    
    	wp_enqueue_script('jquery');
    
    	/* Register theme stylesheets. */
    
    	wp_register_style( 'style', get_stylesheet_uri(), '', '1.0.6' );
    
    	wp_register_style( 'shortcodes', get_template_directory_uri() . '/styles/style-shortcodes.css', '', '1.1' );
    
    	wp_register_style( 'responsive', get_template_directory_uri() . '/styles/style-responsive.css', '', '1.1' );
    
    	wp_register_style( 'sidebarleft', get_template_directory_uri() . '/styles/layouts/thinkup-left-sidebar.css', '', '1.1' );
    
    	wp_register_style( 'sidebarright', get_template_directory_uri() . '/styles/layouts/thinkup-right-sidebar.css', '', '1.1' );
    
    	wp_register_style( 'bootstrap', get_template_directory_uri() . '/lib/extentions/bootstrap/css/bootstrap.min.css', '', '2.3.2' );
    
    	wp_register_style( 'prettyPhoto', get_template_directory_uri().'/lib/extentions/prettyPhoto/css/prettyPhoto.css', '', '3.1.5' ); 
    
    	/* Register Font Packages. */
    
    	wp_register_style( 'font-awesome-min', get_template_directory_uri() . '/lib/extentions/font-awesome/css/font-awesome.min.css', '', '3.2.1' );
    
    	wp_register_style( 'font-awesome-cdn', get_template_directory_uri() . '/lib/extentions/font-awesome-4.2.0/css/font-awesome.min.css', '', '4.2.0' );
    
    	wp_register_style( 'dashicons-css', get_template_directory_uri() . '/lib/extentions/dashicons/css/dashicons.css', '', '2.0' );
    
    	/* Register theme scripts. */
    
    	wp_register_script( 'frontend', get_template_directory_uri() . '/lib/scripts/main-frontend.js', array( 'jquery' ), '1.1', true );
    
    	wp_register_script( 'modernizr', get_template_directory_uri() . '/lib/scripts/modernizr.js', array( 'jquery' ), '', true );
    
    	wp_register_script( 'retina', get_template_directory_uri() . '/lib/scripts/retina.js', array( 'jquery' ), '', true );
    
    	wp_register_script( 'bootstrap', get_template_directory_uri() . '/lib/extentions/bootstrap/js/bootstrap.js', array( 'jquery' ), '2.3.2', true );
    
    	wp_register_script( 'prettyPhoto', ( get_template_directory_uri()."/lib/extentions/prettyPhoto/jquery.prettyPhoto.js" ), array( 'jquery' ), '3.1.5', true );
    
    		/* Add Font Packages */
    
    		wp_enqueue_style( 'font-awesome-min' );
    
    		wp_enqueue_style( 'font-awesome-cdn' );
    
    		wp_enqueue_style( 'dashicons-css' );
    
    		/* Add theme stylesheets */
    
    		wp_enqueue_style( 'bootstrap' );
    
    		wp_enqueue_style( 'prettyPhoto' );
    
    		wp_enqueue_style( 'style' );
    
    		wp_enqueue_style( 'shortcodes' );
    
    		/* Add theme scripts */
    
    		wp_enqueue_script( 'prettyPhoto' );
    
    		wp_enqueue_script( 'frontend' );
    
    		wp_enqueue_script( 'bootstrap' );
    
    		wp_enqueue_script( 'modernizr' );
    
    		if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
    
    			wp_enqueue_script( 'comment-reply' );
    
    		}
    
    		// Add ThinkUpSlider scripts
    
    		if ( is_front_page() or is_thinkuphome() ) {
    
    			wp_enqueue_script( 'thinkupslider', get_template_directory_uri() . '/lib/scripts/plugins/ResponsiveSlides/responsiveslides.min.js', array( 'jquery' ), '1.54' );
    
    		wp_enqueue_script( 'thinkupslider-call', get_template_directory_uri() . '/lib/scripts/plugins/ResponsiveSlides/responsiveslides-call.js', array( 'jquery' ) );
    
    		}
    
    }
    
    add_action( 'wp_enqueue_scripts', 'thinkup_frontscripts', 10 );
    
    /* ----------------------------------------------------------------------------------
    
    	Register Back-End Styles And Scripts
    
    ---------------------------------------------------------------------------------- */
    
    function thinkup_adminscripts() {
    
    	/* Register theme stylesheets. */
    
    	wp_register_style( 'backend', get_template_directory_uri() . '/styles/backend/style-backend.css', '', 1.1 );
    
    	/* Register theme scripts. */
    
    	wp_register_script( 'backend', get_template_directory_uri() . '/lib/scripts/main-backend.js', array( 'jquery' ), '1.1' );
    
    		/* Add theme stylesheets */
    
    		wp_enqueue_style( 'backend' );
    
    		/* Add theme scripts */
    
    		wp_enqueue_script( 'backend' );
    
    }
    
    add_action( 'admin_enqueue_scripts', 'thinkup_adminscripts' );
    
    //----------------------------------------------------------------------------------
    
    //	Register Shortcodes Styles And Scripts
    
    //----------------------------------------------------------------------------------
    
    function thinkup_shortcodescripts() {
    
    	// Register shortcode scripts
    
    	wp_register_script( 'thinkupslider', get_template_directory_uri() . '/lib/scripts/plugins/ResponsiveSlides/responsiveslides.min.js', array( 'jquery' ), '1.54', 'true' );
    
    	wp_register_script( 'thinkupslider-call', get_template_directory_uri() . '/lib/scripts/plugins/ResponsiveSlides/responsiveslides-call.js', array( 'jquery' ), '', 'true' );
    
    		// Add shortcode scripts
    
    		wp_enqueue_script( 'thinkupslider' );
    
    		wp_enqueue_script( 'thinkupslider-call' );
    
    }
    
    add_action( 'wp_enqueue_scripts', 'thinkup_shortcodescripts', 10 );
    
    /* ----------------------------------------------------------------------------------
    
    	Register Theme Widgets
    
    ---------------------------------------------------------------------------------- */
    
    function thinkup_widgets_init() {
    
    	register_sidebar( array(
    
    		'name' => 'Sidebar',
    
    		'id' => 'sidebar-1',
    
    		'before_widget' => '<aside class="widget %2$s">',
    
    		'after_widget' => '</aside>',
    
    		'before_title' => '<h3 class="widget-title">',
    
    		'after_title' => '</h3>',
    
    	) );
    
        register_sidebar( array(
    
            'name' => 'Footer Widget Area 1',
    
            'id' => 'footer-w1',
    
            'before_widget' => '<aside class="widget %2$s">',
    
            'after_widget' => '</aside>',
    
            'before_title' => '<h3 class="footer-widget-title"><span>',
    
            'after_title' => '</span></h3>',
    
        ) );
    
        register_sidebar( array(
    
            'name' => 'Footer Widget Area 2',
    
            'id' => 'footer-w2',
    
            'before_widget' => '<aside class="widget %2$s">',
    
            'after_widget' => '</aside>',
    
            'before_title' => '<h3 class="footer-widget-title"><span>',
    
            'after_title' => '</span></h3>',
    
        ) );
    
        register_sidebar( array(
    
            'name' => 'Footer Widget Area 3',
    
            'id' => 'footer-w3',
    
            'before_widget' => '<aside class="widget %2$s">',
    
            'after_widget' => '</aside>',
    
            'before_title' => '<h3 class="footer-widget-title"><span>',
    
            'after_title' => '</span></h3>',
    
        ) );
    
        register_sidebar( array(
    
            'name' => 'Footer Widget Area 4',
    
            'id' => 'footer-w4',
    
            'before_widget' => '<aside class="widget %2$s">',
    
            'after_widget' => '</aside>',
    
            'before_title' => '<h3 class="footer-widget-title"><span>',
    
            'after_title' => '</span></h3>',
    
        ) );
    
        register_sidebar( array(
    
            'name' => 'Footer Widget Area 5',
    
            'id' => 'footer-w5',
    
            'before_widget' => '<aside class="widget %2$s">',
    
            'after_widget' => '</aside>',
    
            'before_title' => '<h3 class="footer-widget-title"><span>',
    
            'after_title' => '</span></h3>',
    
        ) );
    
        register_sidebar( array(
    
            'name' => 'Footer Widget Area 6',
    
            'id' => 'footer-w6',
    
            'before_widget' => '<aside class="widget %2$s">',
    
            'after_widget' => '</aside>',
    
            'before_title' => '<h3 class="footer-widget-title"><span>',
    
            'after_title' => '</span></h3>',
    
        ) );
    
     }
    
    add_action( 'widgets_init', 'thinkup_widgets_init' );
    Tim Nash

    (@tnash)

    Spam hunter

    In your error logs, when you get the whitescreen, what error is being shown?

    Thread Starter raggie

    (@raggie)

    Fatal error: Cannot redeclare thinkup_input_sliderhome() (previously declared in /wp-content/themes/child_theme/admin/main/options/02.homepage.php:27) in /wp-content/themes/parent_theme/admin/main/options/02.homepage.php on line 27

    And on row 27 is the following code: ¨
    global $thinkup_homepage_sliderswitch;

    I remembered that I copied the whole 02.homepage.php to my child theme. Maybe I should just have the code I want to overwrite in that file?

    Thread Starter raggie

    (@raggie)

    Ok I noticed that the function.php is not the problem. My problem is to overwrite the 02.homepage.php properly. Any ideas what the best solution for removing and overwriting certain parts of that file?

    Tim Nash

    (@tnash)

    Spam hunter

    The quick fix, go into the file in the child theme and remove any “require_once” commands as the parent theme has already loaded the files. If the file has any classes in it they will need to be renamed and then you are good to go.

    Thread Starter raggie

    (@raggie)

    Does not work for me

Viewing 15 replies - 1 through 15 (of 17 total)

The topic ‘problem with "require_once" in child theme’ is closed to new replies.