Change section title in child theme
-
Hi
I’m using child theme with zerif lite as parent theme. I want to change the section’s titles e.g. About us, Our focus, etc. I changed them in the respective section php files e.g. about_us.php, our_focus.php in parent theme folder – it’s okay. However I dont want to touch the parent theme files and instead made a copy to the child theme folder where I made the modification. This way didn’t work though. Please let me know where i,m wrong.Ps, I created child theme using Child theme configurator plugin.
Thanks
-
Hey there methuviem,
Hope you’re well! 🙂
C the link to find the code and copy that code into your child theme’s functions.php.
LINK: https://gist.github.com/calvincanas/071655cc10352a028e0a
It remove the widget created by zerif-lite (parent theme ) then register your own. Just change the name as I put gibberish letters to see if it works fine. 🙂
Hope it helps! 🙂Take care,
CalvinHi Calvin,
Thanks your help. However I tried and it didn’t work.
Here is the code in my child theme’s functions.php. Please could you help to have a look and correct me if I’m wrong.
My site is dichthuatmba.com
Many thanks,
Trinh<?php
// Exit if accessed directly
if ( !defined(‘ABSPATH’)) exit;// BEGIN ENQUEUE PARENT ACTION
if (!function_exists(‘chld_thm_cfg_parent_css’)):
function chld_thm_cfg_parent_css() {
wp_enqueue_style(‘chld_thm_cfg_parent’, get_template_directory_uri() . ‘/style.css’);
}
endif;if (!function_exists(‘chld_thm_cfg_parent_css’)):
function chld_thm_cfg_parent_css() {
wp_enqueue_style(‘chld_thm_cfg_parent’, get_template_directory_uri() . ‘/styles.css’);
}
endif;
add_action(‘wp_enqueue_scripts’, ‘chld_thm_cfg_parent_css’);// END ENQUEUE PARENT ACTION
// !AFTER_SETUP_THEME
add_action( ‘after_setup_theme’, ‘zerif_child_after_setup_theme’ );function zerif_child_after_setup_theme() {
// remove the widget created by parent theme
remove_action( ‘widgets_init’, ‘zerif_widgets_init’ );
// add the widget by child theme
add_action(‘widgets_init’, ‘zerif_child_widgets_init’);function zerif_child_widgets_init()
{register_sidebar(array(
‘name’ => __(‘Sidebar’, ‘zerif-lite’),
‘id’ => ‘sidebar-1’,
‘before_widget’ => ‘<aside id=”%1$s” class=”widget %2$s”>’,
‘after_widget’ => ‘</aside>’,
‘before_title’ => ‘<h1 class=”widget-title”>’,
‘after_title’ => ‘</h1>’,
));
register_sidebar(array(
‘name’ => __(‘Dịch vụ’, ‘zerif-lite’),
‘id’ => ‘sidebar-ourfocus’,
‘before_widget’ => ”,
‘after_widget’ => ”,
‘before_title’ => ‘<h1 class=”widget-title”>’,
‘after_title’ => ‘</h1>’,
));
register_sidebar(array(
‘name’ => __(‘Đánh giá từ khách hàng’, ‘zerif-lite’),
‘id’ => ‘sidebar-testimonials’,
‘before_widget’ => ‘<aside id=”%1$s” class=”widget %2$s”>’,
‘after_widget’ => ‘</aside>’,
‘before_title’ => ‘<h1 class=”widget-title”>’,
‘after_title’ => ‘</h1>’,
));
register_sidebar(array(
‘name’ => __(‘Về chúng tôi’, ‘zerif-lite’),
‘id’ => ‘sidebar-aboutus’,
‘before_widget’ => ”,
‘after_widget’ => ”,
‘before_title’ => ‘<h1 class=”widget-title”>’,
‘after_title’ => ‘</h1>’,
));
register_sidebar(array(
‘name’ => __(‘Đội ngũ’, ‘zerif-lite’),
‘id’ => ‘sidebar-ourteam’,
‘before_widget’ => ”,
‘after_widget’ => ”,
‘before_title’ => ‘<h1 class=”widget-title”>’,
‘after_title’ => ‘</h1>’,
));
}
}
Hi,
Best way would be to also copy the front-page.php to the child theme and change the section URLs. You can rename the sections folder “parts” in the child theme and also do this in front-page.php file. 🙂
Regards,
HardeepHey there guys,
Hope you’re both well today! 🙂
@methuvien – It works fine with me. do you mean that the default sidebars came from parent theme are still there? I suggest you try to name your sidebar with US letters first so we can confirm if this is a character issue.
It would be better if you could take a screenshot of your widgets.
Looking forward for your reply! 🙂
Best Regards,
CalvinIn the child-theme copy of front-page.php, replace all occurrences of the function
get_template_directory()with
get_stylesheet_directory().get_template_directory() always paths to the parent. get_stylesheet_directory() paths to the current child-theme directory.
I was having the same problem with Zerif Lite and was about to pull my hair out when I stumbled upon this difference between the two functions. (I’m a WP theme modding newbie.) So, that’s what fixed it for me. So far so good. If there’s some reason why front-page.php should be pulling from the parent for this theme, I haven’t figured out why. Let me know if you know something I don’t.
Hope this helps someone. I was about to give up on this theme, but I like it so much, I decided to stick to it until solved.
In my child-theme I copied front-page.php, and replaced all occurrences of the function get_template_directory()
with
get_stylesheet_directory().And I added conditional in order to search on the Child Theme directory if the /sections/{section_name}.php existed.
If file_exists, I use the /sections/{section_name}.php from the Child Theme.
If not, I use the one from the parent theme using the get_template_directory() instead.Here’s the code:
<?php get_header(); ?> <?php if ( get_option( 'show_on_front' ) == 'page' ) { ?> <div class="clear"></div> </header> <!-- / END HOME SECTION --> <div id="content" class="site-content"> <div class="container"> <div class="content-left-wrap col-md-9"> <div id="primary" class="content-area"> <main id="main" class="site-main" role="main"> <?php if ( have_posts() ) : ?> <?php /* Start the Loop */ ?> <?php while ( have_posts() ) : the_post(); ?> <?php /* Include the Post-Format-specific template for the content. * If you want to override this in a child theme, then include a file * called content-___.php (where ___ is the Post Format name) and that will be used instead. */ get_template_part( 'content', get_post_format() ); ?> <?php endwhile; ?> <?php zerif_paging_nav(); ?> <?php else : ?> <?php get_template_part( 'content', 'none' ); ?> <?php endif; ?> </main><!-- #main --> </div><!-- #primary --> </div><!-- .content-left-wrap --> <div class="sidebar-wrap col-md-3 content-left-wrap"> <?php get_sidebar(); ?> </div><!-- .sidebar-wrap --> </div><!-- .container --> <?php }else { if(isset($_POST['submitted'])) : /* recaptcha */ $zerif_contactus_sitekey = get_theme_mod('zerif_contactus_sitekey'); $zerif_contactus_secretkey = get_theme_mod('zerif_contactus_secretkey'); $zerif_contactus_recaptcha_show = get_theme_mod('zerif_contactus_recaptcha_show'); if( isset($zerif_contactus_recaptcha_show) && $zerif_contactus_recaptcha_show != 1 && !empty($zerif_contactus_sitekey) && !empty($zerif_contactus_secretkey) ) : $captcha; if( isset($_POST['g-recaptcha-response']) ){ $captcha=$_POST['g-recaptcha-response']; } if( !$captcha ){ $hasError = true; } $response = wp_remote_get( "https://www.google.com/recaptcha/api/siteverify?secret=".$zerif_contactus_secretkey."&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR'] ); if($response['body'].success==false) { $hasError = true; } endif; /* name */ if(trim($_POST['myname']) === ''): $nameError = __('* Please enter your name.','zerif-lite'); $hasError = true; else: $name = trim($_POST['myname']); endif; /* email */ if(trim($_POST['myemail']) === ''): $emailError = __('* Please enter your email address.','zerif-lite'); $hasError = true; elseif (!preg_match("/^:alnum:[a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", trim($_POST['myemail']))) : $emailError = __('* You entered an invalid email address.','zerif-lite'); $hasError = true; else: $email = trim($_POST['myemail']); endif; /* subject */ if(trim($_POST['mysubject']) === ''): $subjectError = __('* Please enter a subject.','zerif-lite'); $hasError = true; else: $subject = trim($_POST['mysubject']); endif; /* message */ if(trim($_POST['mymessage']) === ''): $messageError = __('* Please enter a message.','zerif-lite'); $hasError = true; else: $message = stripslashes(trim($_POST['mymessage'])); endif; /* send the email */ if(!isset($hasError)): $zerif_contactus_email = get_theme_mod('zerif_contactus_email'); if( empty($zerif_contactus_email) ): $emailTo = get_theme_mod('zerif_email'); else: $emailTo = $zerif_contactus_email; endif; if(isset($emailTo) && $emailTo != ""): if( empty($subject) ): $subject = 'From '.$name; endif; $body = "Name: $name \n\nEmail: $email \n\n Subject: $subject \n\n Message: $message"; $headers = 'From: '.$name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email; wp_mail($emailTo, $subject, $body, $headers); $emailSent = true; else: $emailSent = false; endif; endif; endif; $zerif_bigtitle_show = get_theme_mod('zerif_bigtitle_show'); $big_title_child = get_stylesheet_directory() . "/sections/big_title.php"; $big_title_parent = get_template_directory() . "/sections/big_title.php"; if( isset($zerif_bigtitle_show) && $zerif_bigtitle_show != 1 ){ if (file_exists($big_title_child)) { include get_stylesheet_directory() . "/sections/big_title.php"; } else { include get_template_directory() . "/sections/big_title.php"; } } ?> </header> <!-- / END HOME SECTION --> <div id="content" class="site-content"> <?php /* OUR FOCUS SECTION */ $zerif_ourfocus_show = get_theme_mod('zerif_ourfocus_show'); $on_focus_child = get_stylesheet_directory() . "/sections/our_focus.php"; $on_focus_parent = get_template_directory() . "/sections/our_focus.php"; if( isset($zerif_ourfocus_show) && $zerif_ourfocus_show != 1 ){ if (file_exists($on_focus_child)) { include get_stylesheet_directory() . "/sections/our_focus.php"; } else { include get_template_directory() . "/sections/our_focus.php"; } } /* RIBBON WITH BOTTOM BUTTON */ $ribbon_with_bottom_button_child = get_stylesheet_directory() . "/sections/ribbon_with_bottom_button.php"; $ribbon_with_bottom_button_parent = get_template_directory() . "/sections/ribbon_with_bottom_button.php"; if (file_exists($ribbon_with_bottom_button_child)) { include get_stylesheet_directory() . "/sections/ribbon_with_bottom_button.php"; } else { include get_template_directory() . "/sections/ribbon_with_bottom_button.php"; } /* ABOUT US */ $zerif_aboutus_show = get_theme_mod('zerif_aboutus_show'); $about_us_child = get_stylesheet_directory() . "/sections/about_us.php"; $about_us_parent = get_template_directory() . "/sections/about_us.php"; if( isset($zerif_aboutus_show) && $zerif_aboutus_show != 1 ){ if (file_exists($about_us_child)) { include get_stylesheet_directory() . "/sections/about_us.php"; } else { include get_template_directory() . "/sections/about_us.php"; } } /* OUR TEAM */ $zerif_ourteam_show = get_theme_mod('zerif_ourteam_show'); $our_team_child = get_stylesheet_directory() . "/sections/our_team.php"; $our_team_parent = get_template_directory() . "/sections/our_team.php"; if( isset($zerif_ourteam_show) && $zerif_ourteam_show != 1 ){ if (file_exists($our_team_child)) { include get_stylesheet_directory() . "/sections/our_team.php"; } else { include get_template_directory() . "/sections/our_team.php"; } } /* TESTIMONIALS */ $zerif_testimonials_show = get_theme_mod('zerif_testimonials_show'); $testimonials_child = get_stylesheet_directory() . "/sections/testimonials.php"; $testimonials_parent = get_template_directory() . "/sections/testimonials.php"; if( isset($zerif_testimonials_show) && $zerif_testimonials_show != 1 ){ if (file_exists($testimonials_child)) { include get_stylesheet_directory() . "/sections/testimonials.php"; } else { include get_template_directory() . "/sections/testimonials.php"; } } /* RIBBON WITH RIGHT SIDE BUTTON */ $ribbon_with_right_button_child = get_stylesheet_directory() . "/sections/ribbon_with_right_button.php"; $ribbon_with_right_button_parent = get_template_directory() . "/sections/ribbon_with_right_button.php"; if (file_exists($ribbon_with_right_button_child)) { include get_stylesheet_directory() . "/sections/ribbon_with_right_button.php"; } else { include get_template_directory() . "/sections/ribbon_with_right_button.php"; } /* LATEST NEWS */ $zerif_latestnews_show = get_theme_mod('zerif_latestnews_show'); $latest_news_child = get_stylesheet_directory() . "/sections/latest_news.php"; $latest_news_parent = get_template_directory() . "/sections/latest_news.php"; if( isset($zerif_latestnews_show) && $zerif_latestnews_show != 1 ){ if (file_exists($latest_news_child)) { include get_stylesheet_directory() . "/sections/latest_news.php"; } else { include get_template_directory() . "/sections/latest_news.php"; } } /* CONTACT US */ $zerif_contactus_show = get_theme_mod('zerif_contactus_show'); if( isset($zerif_contactus_show) && $zerif_contactus_show != 1 ): ?> <section class="contact-us" id="contact"> <div class="container"> <!-- SECTION HEADER --> <div class="section-header"> <?php $zerif_contactus_title = get_theme_mod('zerif_contactus_title','Get in touch'); if ( !empty($zerif_contactus_title) ): echo '<h2 class="white-text">'.$zerif_contactus_title.'</h2>'; endif; $zerif_contactus_subtitle = get_theme_mod('zerif_contactus_subtitle'); if(isset($zerif_contactus_subtitle) && $zerif_contactus_subtitle != ""): echo '<h6 class="white-text">'.$zerif_contactus_subtitle.'</h6>'; endif; ?> </div> <!-- / END SECTION HEADER --> <!-- CONTACT FORM--> <div class="row"> <?php if(isset($emailSent) && $emailSent == true) : echo '<p class="error white-text">'.__('Thanks, your email was sent successfully!','zerif-lite').'</p>'; elseif(isset($_POST['submitted'])): echo '<p class="error white-text">'.__('Sorry, an error occured.','zerif-lite').'<p>'; endif; if(isset($nameError) && $nameError != '') : echo '<p class="error white-text">'.$nameError.'</p>'; endif; if(isset($emailError) && $emailError != '') : echo '<p class="error white-text">'.$emailError.'</p>'; endif; if(isset($subjectError) && $subjectError != '') : echo '<p class="error white-text">'.$subjectError.'</p>'; endif; if(isset($messageError) && $messageError != '') : echo '<p class="error white-text">'.$messageError.'</p>'; endif; ?> <form role="form" method="POST" action="" onSubmit="this.scrollPosition.value=document.body.scrollTop" class="contact-form"> <input type="hidden" name="scrollPosition"> <input type="hidden" name="submitted" id="submitted" value="true" /> <div class="col-lg-4 col-sm-4" data-scrollreveal="enter left after 0s over 1s"> <input type="text" name="myname" placeholder="Your Name" class="form-control input-box" value="<?php if(isset($_POST['myname'])) echo $_POST['myname'];?>"> </div> <div class="col-lg-4 col-sm-4" data-scrollreveal="enter left after 0s over 1s"> <input type="email" name="myemail" placeholder="Your Email" class="form-control input-box" value="<?php if(isset($_POST['myemail'])) echo $_POST['myemail'];?>"> </div> <div class="col-lg-4 col-sm-4" data-scrollreveal="enter left after 0s over 1s"> <input type="text" name="mysubject" placeholder="Subject" class="form-control input-box" value="<?php if(isset($_POST['mysubject'])) echo $_POST['mysubject'];?>"> </div> <div class="col-md-12" data-scrollreveal="enter right after 0s over 1s"> <textarea name="mymessage" class="form-control textarea-box" placeholder="Your Message"><?php if(isset($_POST['mymessage'])) { echo stripslashes($_POST['mymessage']); } ?></textarea> </div> <?php $zerif_contactus_button_label = get_theme_mod('zerif_contactus_button_label','Send Message'); if( !empty($zerif_contactus_button_label) ): echo '<button class="btn btn-primary custom-button red-btn" type="submit" data-scrollreveal="enter left after 0s over 1s">'.$zerif_contactus_button_label.'</button>'; endif; ?> <?php $zerif_contactus_sitekey = get_theme_mod('zerif_contactus_sitekey'); $zerif_contactus_secretkey = get_theme_mod('zerif_contactus_secretkey'); $zerif_contactus_recaptcha_show = get_theme_mod('zerif_contactus_recaptcha_show'); if( isset($zerif_contactus_recaptcha_show) && $zerif_contactus_recaptcha_show != 1 && !empty($zerif_contactus_sitekey) && !empty($zerif_contactus_secretkey) ) : echo '<div class="g-recaptcha" data-sitekey="' . $zerif_contactus_sitekey . '"></div>'; endif; ?> </form> </div> <!-- / END CONTACT FORM--> </div> <!-- / END CONTAINER --> </section> <!-- / END CONTACT US SECTION--> <?php endif; } get_footer(); ?>
The topic ‘Change section title in child theme’ is closed to new replies.
