How to override function in parent theme?
-
In template-tags.php in parent theme, I found such code
add_action( ‘onepress_site_start’, ‘onepress_site_header’ );
if ( ! function_exists( ‘onepress_site_header’ ) ) {
/**
* Display site header
*/
function onepress_site_header(){
$header_width = get_theme_mod( ‘onepress_header_width’, ‘contained’ );
$is_disable_sticky = sanitize_text_field( get_theme_mod( ‘onepress_sticky_header_disable’ ) );
$classes = array(
‘site-header’, ‘header-‘.$header_width,
);if ( $is_disable_sticky != 1 ) {
$classes[] =’is-sticky no-scroll’;
} else {
$classes[] =’no-sticky no-scroll’;
}$transparent = ‘no-t’;
if ( onepress_is_transparent_header() ){
$transparent = ‘is-t’;
}
$classes[] = $transparent;$pos = sanitize_text_field(get_theme_mod(‘onepress_header_position’, ‘top’));
if ($pos == ‘below_hero’) {
$classes[] = ‘h-below-hero’;
} else {
$classes[] = ‘h-on-top’;
}?>
<header id=”masthead” class=”<?php echo esc_attr( join(‘ ‘, $classes ) ); ?>” role=”banner”>
<div class=”container”>
<div class=”site-branding”>
<?php
onepress_site_logo();
?>
</div>
<div class=”headerMenuBar”>
<ul class=”headerMenuUl”>
<?php
dynamic_sidebar(‘header-menu’);
?></div>
<div class=”header-right-wrapper”><?php _e(‘Menu’, ‘onepress’); ?><span></span>
<nav id=”site-navigation” class=”main-navigation” role=”navigation”>
<ul class=”onepress-menu”>
<?php wp_nav_menu(array(‘theme_location’ => ‘primary’, ‘container’ => ”, ‘items_wrap’ => ‘%3$s’)); ?></nav>
<!– #site-navigation –>
</div>
</div>
</header><!– #masthead –>
<?php
}
}I want to override that function into my child theme. I have made a php file with the same name in child theme
add_action( ‘onepress_site_start’, ‘onepress_site_header’ );
function onepress_site_header(){
$header_width = get_theme_mod( ‘onepress_header_width’, ‘contained’ );
$is_disable_sticky = sanitize_text_field( get_theme_mod( ‘onepress_sticky_header_disable’ ) );
$classes = array(
‘site-header’, ‘header-‘.$header_width,
);if ( $is_disable_sticky != 1 ) {
$classes[] =’is-sticky no-scroll’;
} else {
$classes[] =’no-sticky no-scroll’;
}$transparent = ‘no-t’;
if ( onepress_is_transparent_header() ){
$transparent = ‘is-t’;
}
$classes[] = $transparent;$pos = sanitize_text_field(get_theme_mod(‘onepress_header_position’, ‘top’));
if ($pos == ‘below_hero’) {
$classes[] = ‘h-below-hero’;
} else {
$classes[] = ‘h-on-top’;
}?>
<header id=”masthead” class=”<?php echo esc_attr( join(‘ ‘, $classes ) ); ?>” role=”banner”>
<div class=”container”>
<div class=”site-branding”>
<?php
onepress_site_logo();
?>
</div><div class=”header-right-wrapper”>
<?php _e(‘Menu’, ‘onepress’); ?><span></span>
<div class=”headerMenuBar”>
<ul class=”headerMenuUl”>
<?php
dynamic_sidebar(‘header-menu’);
?></div>
<nav id=”site-navigation” class=”main-navigation” role=”navigation”>
<ul class=”onepress-menu”>
<?php wp_nav_menu(array(‘theme_location’ => ‘primary’, ‘container’ => ”, ‘items_wrap’ => ‘%3$s’)); ?></nav>
<!– #site-navigation –>
</div>
</div>
</header><!– #masthead –>
<?php
}difference is I changed position of dynamic_sidebar()
I can’t override function. Nothing changes. Why?
- The topic ‘How to override function in parent theme?’ is closed to new replies.