badget

Biggest Sale! Special Offer!

Get 30% discount on all of our single themes with this coupon code: #30%SALE

Hurry up! *Limited time offer*

Override parent theme function through the child theme

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #52254
    stanlin1999
    Participant

    Trying to create a template that places a custom post UI image between the navigation bar and the title like this:

    intended outcome

    However, I am unable to override the header-extensions.php in my child folder to the parent

    The page is displayed through single-program.php -> get_header(); -> header-extensions.php -> ambition_headercontent_details();

    The code that is fit between the Navbar and the title:

    		</div><!-- .container -->
    
    		<img id="single-program-banner" src="<?php the_field('banner'); ?>" alt="" />
    
    		
    	</div><!-- .hgroup-wrap -->

    Theme I’m using https://www.themehorse.com/preview/ambition/

    Thank you

    I tried looking at this post (# but when I create a functions.php file in my child folder, my page goes blank.

    #52274

    Hi stanlin1999,

    Creating the same structure in the child theme will not over ride the parent theme. First of all you need to unhook the function and then customize the code. We will post a simple example how to unhook to functions:-
    Create a two files styles.css and functions.php

    Under style.css add this following code.

    /*
    Theme Name: Ambition Child Theme
    Theme URI: https://www.themehorse.com/themes/ambition
    Author: Theme Horse
    Author URI: https://www.themehorse.com
    Text Domain: ambition
    Template: ambition
    */
    
    @import url("../ambition/style.css"); 

    Under functions.php file

    // Unhook default Thematic functions
    function unhook_thematic_functions() {
        // Don't forget the position number if the original function has one
    
    add_action('ambition_header', 'ambition_headercontent_details', 10);
    }
    
    add_action('init','unhook_thematic_functions');
    add_action( 'ambition_headercontent_details', 'ambition_child_headercontent_details', 10 );
    funtion ambition_child_headercontent_details(){
    // your stuff
    }

    Thank you!

    #52281
    stanlin1999
    Participant

    Hi, thank you for your help.

    I tried using your example code above for the functions.php, however, when I use it my site crashes

    This page isn’t working
    
    localhost is currently unable to handle this request.
    HTTP ERROR 500

    This is what my functions.php looks like. It is in my child folder ambition-child.

    
    <?php  
    
    // Unhook default Thematic functions
    function unhook_thematic_functions() {
        // Don't forget the position number if the original function has one
    
    add_action('ambition_header', 'ambition_headercontent_details', 10);
    }
    
    add_action('init','unhook_thematic_functions');
    add_action( 'ambition_headercontent_details', 'ambition_child_headercontent_details', 10 );
    function ambition_child_headercontent_details(){
    
    		<div>
    			<img id="single-program-banner" src="<?php the_field('banner'); ?>" alt="" />
    
    		</div>	
    
    }
    
    ?>
    #52282
    stanlin1999
    Participant

    I was able to find a solution!!

    I think you had a similar idea, but the answer in the following link added back the ambition_child_headercontent_details function in the child theme.

    https://wordpress.stackexchange.com/questions/273941/how-to-override-parent-theme-function-through-the-child-theme

    Cheers,

    #52283
    stanlin1999
    Participant

    Weird, now when I try to public or preview pages, the page just hangs..

    #52288

    Hi stanlin1999,

    I have readded the action hook code which must be added in the child theme functions.php file.

    <?php 
    // Unhook default Thematic functions
    function unhook_thematic_functions() {
        // Don't forget the position number if the original function has one
    remove_action('ambition_header', 'ambition_headercontent_details', 10);
    }
    
    add_action('init','unhook_thematic_functions');
    add_action( 'ambition_header', 'ambition_child_headercontent_details', 10 );
    function ambition_child_headercontent_details(){global $ambition_settings;
    	$header_image = get_header_image();
    	if (!empty($header_image)):?>
    			<a href="<?php echo esc_url(home_url('/'));?>"><img src="<?php echo esc_url($header_image);?>" class="header-image" width="<?php echo get_custom_header()->width;?>" height="<?php echo get_custom_header()->height;?>" alt="<?php echo esc_attr(get_bloginfo('name', 'display'));?>"> 
    			</a>
    	<?php
    		endif;?>
    	<div class="hgroup-wrap">
    		<div class="container clearfix">
    		<?php
    		$ambition_settings = wp_parse_args(  get_option( 'ambition_theme_settings', array() ),  ambition_get_option_defaults() );
    			$header_display = $ambition_settings['header_settings'];
    			$header_logo = $ambition_settings['img-upload-header-logo'];
    			if ($header_display != 'disable_both' && $header_display == 'header_text') { ?>
    			<section id="site-logo" class="clearfix">
    			<?php if(is_single() || (!is_page_template('page-templates/page-template-business.php' )) && !is_home()){ ?>
    				<h2 id="site-title"> 
    					<a href="<?php echo esc_url(home_url('/'));?>" title="<?php echo esc_attr(get_bloginfo('name', 'display'));?>" rel="home">
    					<?php bloginfo('name');?>
    					</a> 
    				</h2><!-- #site-title -->
    				<?php } else { ?>
    				<h1 id="site-title"> 
    					<a href="<?php echo esc_url(home_url('/'));?>" title="<?php echo esc_attr(get_bloginfo('name', 'display'));?>" rel="home">
    					<?php bloginfo('name');?>
    					</a> 
    				</h1><!-- #site-title -->
    				<?php }
    				$site_description = get_bloginfo( 'description', 'display' );
    				if($site_description){?>
    					<h2 id="site-description"> <?php bloginfo('description');?> </h2>
    				<?php } ?>
    			</section><!-- #site-logo -->
    				<?php
    			}	elseif ($header_display != 'disable_both' && $header_display == 'header_logo') {
    				?>
    			<section id="site-logo" class="clearfix">
    			<?php if(is_single() || (!is_page_template('page-templates/page-template-business.php' )) && !is_home()){ ?>
    				<h2 id="site-title">
    					<a href="<?php echo esc_url(home_url('/'));?>" title="<?php echo esc_attr(get_bloginfo('name', 'display'));?>" rel="home"> <img src="<?php echo $header_logo;?>" alt="<?php echo esc_attr(get_bloginfo('name', 'display'));?>"></a>
    				</h2>
    				<?php }else{ ?>
    				<h1 id="site-title">
    					<a href="<?php echo esc_url(home_url('/'));?>" title="<?php echo esc_attr(get_bloginfo('name', 'display'));?>" rel="home"> <img src="<?php echo $header_logo;?>" alt="<?php echo esc_attr(get_bloginfo('name', 'display'));?>"></a>
    				</h1>
    				<?php } ?>
    			</section><!-- #site-logo -->
    			<?php }?>
    			<button class="menu-toggle"><?php _e('Responsive Menu', 'ambition' ); ?></button>
    			<?php  
    			if (has_nav_menu('primary')) {// if there is nav menu then content displayed from nav menu else from pages ?>
    			<section class="hgroup-right">
    			<?php $args = array(
    						'theme_location' => 'primary',
    						'container'      => '',
    						'items_wrap'     => '<ul class="nav-menu">%3$s</ul>',
    					); ?>
    				<nav id="site-navigation" class="main-navigation clearfix" role="navigation">
    					<?php wp_nav_menu($args);//extract the content from apperance-> nav menu ?>
    				</nav><!-- #access -->
    		<?php } else {// extract the content from page menu only ?>
    			<section class="hgroup-right">
    				<nav id="site-navigation" class="main-navigation clearfix" role="navigation">
    					<?php	wp_page_menu(array('menu_class' => 'nav-menu')); ?>
    				</nav><!-- #access -->
    			<?php	}
    			$search_form = $ambition_settings['search_header_settings'];
    			if (1 != $search_form) { ?>
    				<div class="search-toggle"></div><!-- .search-toggle -->
    				<div id="search-box" class="hide">
    					<?php get_search_form();?>
    					<span class="arrow"></span>
    				</div><!-- #search-box -->
    						<?php } ?>
    			</section><!-- .hgroup-right -->
    		</div><!-- .container -->
    	</div><!-- .hgroup-wrap -->
    
    			<?php global $disable_slider;
    				global $ambition_settings;
    			if (is_front_page()) {
    				$disable_slider = $ambition_settings['disable_slider'];
    				if (empty($disable_slider)) {
    					if (function_exists('ambition_pass_slider_effect_cycle_parameters')) {
    						ambition_pass_slider_effect_cycle_parameters();
    					}
    					if (function_exists('ambition_featured_sliders')) {
    						ambition_featured_sliders();
    					}
    				}
    			} else {
    				if (('' != ambition_header_title()) || function_exists('bcn_display_list')) {
    					$sitetitle_img_setting = $ambition_settings['site_title_setting'];
    
    					$sitetitle_image = $ambition_settings['img-upload-site-title']; ?>
    					<div class="page-title-wrap" <?php if ( $sitetitle_img_setting != '1'  && $sitetitle_image != '' ){ ?> style="background-image:url('<?php echo esc_url($sitetitle_image);?>');" <?php } ?> >
    						<div class="container clearfix">
    						<?php if(is_home()){?>
    							<h2 class="page-title"><?php echo ambition_header_title();?></h2><!-- .page-title -->
    						<?php } else { ?>
    							<h1 class="page-title"><?php echo ambition_header_title();?></h1><!-- .page-title -->
    						<?php }
    							if (function_exists('ambition_breadcrumb')) {
    								ambition_breadcrumb();
    							}
    						?>
    						</div><!-- .container -->
    					</div><!-- .page-title-wrap -->
    			<?php
    				}
    			}
    }
    
    ?>

    This will overwrite the parent header-extension.php file. You can customize in functions.php file as per your needs.
    I am not sure what this code is for or is it from plugins. If you have added it unknownly then it will give Uncaught Error: Call to undefined function the_field() which is not a known function.

    <div>
    			<img id="single-program-banner" src="<?php the_field('banner'); ?>" alt="" />
    
    		</div>

    Thank you!

    #52299
    stanlin1999
    Participant

    the the_field() is a custom field type function. I was able to get it working!

    Turns out I have an extra whitespace right before <?php and it was throwing the error: ‘Cannot modify header information – headers already sent by’ Found the solution here:

    https://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php

    It’s great to see that you are able to offer help and support this fantastic theme 😀

    #52325

    That’s great and thanks for sharing your information with us.

    Thank you!

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.