Child Themes – PHP Question
-
I have made several child themes in the past, but I pretty much only modified CSS. With a current project I want to change a line in home.php. With CSS I could import the original style.css and make only the changes I wanted. I can’t figure out how to do this with PHP.
For example, I have home.php that looks like this:
<?php get_header(); ?> <?php if ( is_home() && get_option('aggregate_featured') == 'on' ) get_template_part('includes/featured','home'); ?> <?php if ( is_active_sidebar( 'homepage-recentfrom-area-1' ) || is_active_sidebar( 'homepage-recentfrom-area-2' ) || is_active_sidebar( 'homepage-recentfrom-area-3' ) ) { ?> <?php if ( is_active_sidebar( 'homepage-recentfrom-area-1' ) && !dynamic_sidebar('homepage-recentfrom-area-1') ) : ?> <?php endif; ?> <?php if ( is_active_sidebar( 'homepage-recentfrom-area-2' ) && !dynamic_sidebar('homepage-recentfrom-area-2') ) : ?> <?php endif; ?> <?php if ( is_active_sidebar( 'homepage-recentfrom-area-3' ) && !dynamic_sidebar('homepage-recentfrom-area-3') ) : ?> <?php endif; ?> <div class="clear"></div> <?php } ?> <div id="main-content" class="clearfix"> <div id="left-area"> <h4 class="main-title"><?php esc_html_e('Most Recent Articles','Aggregate'); ?></h4> <div id="entries"> <?php get_template_part('includes/entry','home'); ?> </div> <!-- end #entries --> </div> <!-- end #left-area --> <?php if ( is_active_sidebar( 'homepage-sidebar' ) ) { ?> <div id="sidebar"> <?php if ( !dynamic_sidebar('homepage-sidebar') ) : ?> <?php endif; ?> </div> <!-- #sidebar --> <?php } else { ?> <?php get_sidebar(); ?> <?php } ?> <?php get_footer(); ?>
I simply want to change:
<h4 class="main-title"><?php esc_html_e('Most Recent Articles','Aggregate'); ?></h4>
with:
<h4 class="main-title"><?php esc_html_e('News and Announcements','Aggregate'); ?></h4>
I understand that I can simply copy and paste the entire home.php file to my child theme directory and make the simple change, but that overrides the ENTIRE home.php in the original theme. If a theme update comes along and makes changes, I wouldn’t know.
- The topic ‘Child Themes – PHP Question’ is closed to new replies.