I am currently working on a website using WordPress and the ColorMag theme and I'd like to modify the basic theme using a child theme (Child Theme Modificator).
What I need to modify is the colormag_below_header_bar_display (line 478) function by adding a language toggle like this:
if ( ! function_exists( 'colormag_below_header_bar_display' ) ) :
/**
* Function to display the middle header bar.
*
* @since ColorMag 1.2.2
*/
function colormag_below_header_bar_display() {
$random_post_icon = get_theme_mod( 'colormag_random_post_in_menu', 0 );
$search_icon = get_theme_mod( 'colormag_search_icon_in_menu', 0 );
?>
<nav id="site-navigation" class="main-navigation clearfix" role="navigation">
<div class="inner-wrap clearfix">
<?php
if ( 1 == get_theme_mod( 'colormag_home_icon_display', 0 ) ) {
$home_icon_class = 'home-icon';
if ( is_front_page() ) {
$home_icon_class = 'home-icon front_page_on';
}
?>
<div class="<?php echo esc_attr( $home_icon_class ); ?>">
<a href="<?php echo esc_url( home_url( '/' ) ); ?>"
title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>"
>
<i class="fa fa-home"></i>
</a>
</div>
<?php } ?>
<?php if ( 1 == $random_post_icon || 1 == $search_icon ) { ?>
<div class="search-random-icons-container">
<?php
// Displays the random post.
if ( 1 == $random_post_icon ) {
colormag_random_post();
}
// Displays the search icon.
if ( 1 == $search_icon ) {
?>
<div class="top-search-wrap">
<i class="fa fa-search search-top"></i>
<div class="search-form-top">
<?php get_search_form(); ?>
</div>
</div>
<?php pll_the_languages(array('show_flags' => 1, 'show_names' => 1, 'hide_current' => 1 ) ); ?>
<?php } ?>
</div>
<?php } ?>
<p class="menu-toggle"></p>
<?php
if ( has_nav_menu( 'primary' ) ) {
wp_nav_menu(
array(
'theme_location' => 'primary',
'container_class' => 'menu-primary-container',
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
)
);
} else {
wp_page_menu();
}
?>
</div>
</nav>
<?php
}
endif;
The part that I added is: <?php pll_the_languages(array('show_flags' => 1, 'show_names' => 1, 'hide_current' => 1 ) ); ?>
, which is a function steming from the Polylang plugin.
When editing this file in the normal theme, everything works and the language switcher is visible in the right part of the navigation bar - however it is not visible on the child theme.
When I try to do this via the Child Theme Modificator plugin, the file that the function is located in (inc/template-tags.php), is not selectable as a file to transfer to the child theme:
Manually copying the modified version into the child theme via FTP did not work either. The modified version of my function does not seem to be used in that case.
I am quite new to WordPress/PHP and the creation of child themes, so any help would be greatly appreciated.
question from:
https://stackoverflow.com/questions/65859631/unable-to-override-function-in-wordpress-child-theme 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…