Site logo

Archived topic

Override functions.php in child themes

1 reply · Started by Anonymous on March 23, 2015

Viewing posts 1–2 of 2

Hello.

I am making a child theme based on your excellent GeneratePress theme. One of the things I want to do is to override the function generate_get_defaults(), however when I upgrade GeneratePress i of course get an error because I cannot re-declare the function.

Would it be possible to encase this in a if (!function_exists()) clause like

if (!function_exists('generate_get_defaults')){
	function generate_get_defaults()
	{
		$generate_defaults = array(
			'hide_title' => '',
			'hide_tagline' => '',
			'logo' => '',
			'container_width' => '1100',
			'header_layout_setting' => 'fluid-header',
			'nav_alignment_setting' => 'left',
			'header_alignment_setting' => 'left',
			'nav_layout_setting' => 'fluid-nav',
			'nav_position_setting' => 'nav-below-header',
			'nav_search' => 'disable',
			'content_layout_setting' => 'separate-containers',
			'layout_setting' => 'right-sidebar',
			'blog_layout_setting' => 'right-sidebar',
			'single_layout_setting' => 'right-sidebar',
			'post_content' => 'full',
			'footer_layout_setting' => 'fluid-footer',
			'footer_widget_setting' => '3',
			'background_color' => '#efefef',
			'text_color' => '#3a3a3a',
			'link_color' => '#1e73be',
			'link_color_hover' => '#000000',
			'link_color_visited' => '',
		);
		
		return apply_filters( 'generate_option_defaults', $generate_defaults );
	}
}

That is the one function I have found would be useful to alter in my child. There may of course be others that would benefit from being overridden in child themes, but I haven't found any yet.

Hi there,

You can actually use the filter attached to that function.

For example, this is from our "Exhibit" child theme:

if ( !function_exists( 'exhibit_exhibit_defaults' ) ) :
	add_filter( 'generate_option_defaults','exhibit_exhibit_defaults' );
	function exhibit_exhibit_defaults()
	{
		$exhibit_defaults = array(
			'hide_title' => '',
			'hide_tagline' => '',
			'logo' => '',
			'container_width' => '1220',
			'header_layout_setting' => 'fluid-header',
			'center_header' => 'true',
			'center_nav' => 'true',
			'nav_alignment_setting' => 'center',
			'header_alignment_setting' => 'center',
			'nav_layout_setting' => 'fluid-nav',
			'nav_position_setting' => 'nav-below-header',
			'nav_search' => 'enable',
			'content_layout_setting' => 'separate-containers',
			'layout_setting' => 'right-sidebar',
			'blog_layout_setting' => 'right-sidebar',
			'single_layout_setting' => 'right-sidebar',
			'post_content' => 'full',
			'footer_layout_setting' => 'fluid-footer',
			'footer_widget_setting' => '3',
			'background_color' => '#9e9e9e',
			'text_color' => '#3a3a3a',
			'link_color' => '#1e73be',
			'link_color_hover' => '#222222',
			'link_color_visited' => '',
		);
		
		return $exhibit_defaults;
	}
endif;

Hope this helps :)

This archived topic is closed to new replies.