0

I have set up a child theme to make custom changes to my site without having them erased every time I update. One change is to remove a wrapper that displays the title of the page with a lot of white space around it in the "content-hero.php" file. The code from the parent file is:

<div class="hero <?php echo edin_additional_class(); ?>">
<?php if ( ! is_page_template( 'page-templates/front-page.php' ) ) : ?>

    <?php the_title( '<div class="hero-wrapper"><h1 class="page-title">', '</h1></div>' ); ?>

<?php else : ?>

    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
        <?php
            if ( 1 == get_theme_mod( 'edin_title_front_page' ) ) {
                the_title( '<header class="entry-header"><h1 class="page-title">', '</h1></header>' );
            }
        ?>
        <div class="entry-content">
            <?php the_content(); ?>
            <?php
                wp_link_pages( array(
                    'before'      => '<div class="page-links">' . __( 'Pages:', 'edin' ),
                    'after'       => '</div>',
                    'link_before' => '<span>',
                    'link_after'  => '</span>',
                ) );
            ?>
        </div><!-- .entry-content -->
        <?php edit_post_link( __( 'Edit', 'edin' ), '<footer class="entry-footer"><span class="edit-link">', '</span></footer>' ); ?>
    </article><!-- #post-## -->

<?php endif; ?>

I simply comment all of this out in the parent file using <!-- -->

But every time I update the theme this will be erased. Is there a code I can put in the functions.php (or style.css) file in the child theme to prevent this from loading?

2
  • 2
    If you make a content-hero.php in the child theme does it not override the one in the parent theme? Commented Nov 30, 2014 at 0:01
  • Yes, I totally could do that, and it will work. I was hoping for a solution other than that because if the original is updated those updates wouldn't be reflected in the copied version unless I manually updated it, which this is trying to avoid in the first place. I would also rather keep from having duplicate files of all the things I want to change if I can.
    – JMF
    Commented Nov 30, 2014 at 3:10

1 Answer 1

0

No, unfortunately this is inherent limitation of PHP templates used in WordPress natively. You will have to override either this template file, or file(s) which include it, but in any case something will have to be replaced on whole file scope.

There is no clean way to load template file partially in WordPress, which is handled by template inheritance concept in alternate templating engines.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.