• Resolved Omorgan

    (@omorgan)


    Hi Guys,

    I’m new to WordPress, trying out a localhost install to experiment and learn (hopefully for a larger project in due course).

    I want to know how create a child php file that will allow me to insert code into an area of the footer.php of my parent theme…..

    I am using the Qwerty Theme from SevenBold.com. I want to add my Copyright element in the footer. The theme come with three footer widget areas, but I hate the alignment of the text when doing it this way.

    I do however like the alignment of the ‘Qwerty Theme by Seven Bold’ so i went into the footer.php and found this code:

    <?php
    /**
     * The template for displaying the footer.
     *
     * Contains the closing of the #content div and all content after
     *
     * @package qwerty
     */
    ?>
    
    	</div><!-- #content -->
    
    	<?php get_sidebar(); ?>
    
    	<footer id="colophon" class="site-footer" role="contentinfo">
    		<div class="site-info">
    			<?php printf( __( '<a href="https://sevenbold.com/wordpress/qwerty/">%1$s Theme</a> <i>by</i> %2$s', 'qwerty' ), 'Qwerty', '<a href="https://sevenbold.com/wordpress/" rel="designer">Seven Bold</a>' ); ?>
    		</div><!-- .site-info -->
    	</footer><!-- #colophon -->
    </div><!-- #page -->
    
    <?php wp_footer(); ?>
    
    </body>
    </html>

    I got the exact effect I wanted by inserting the line:

    <?php printf( __( ' <br \> Copyright M&E Events Ltd. 2016 Company Number XXXXXXX Vat Number XXXXXXX <br \> <br \>' )); ?>

    Directly above the theme link

    making:

    <?php
    /**
     * The template for displaying the footer.
     *
     * Contains the closing of the #content div and all content after
     *
     * @package qwerty
     */
    ?>
    
    	</div><!-- #content -->
    
    	<?php get_sidebar(); ?>
    
    	<footer id="colophon" class="site-footer" role="contentinfo">
    		<div class="site-info">
    			<?php printf( __( ' <br \> Copyright M&E Events Ltd. 2016 Company Number XXXXXXX Vat Number XXXXXXX <br \> <br \>' )); ?>
    			<?php printf( __( '<a href="https://sevenbold.com/wordpress/qwerty/">%1$s Theme</a> <i>by</i> %2$s', 'qwerty' ), 'Qwerty', '<a href="https://sevenbold.com/wordpress/" rel="designer">Seven Bold</a>' ); ?>
    		</div><!-- .site-info -->
    	</footer><!-- #colophon -->
    </div><!-- #page -->
    
    <?php wp_footer(); ?>
    
    </body>
    </html>

    All is well, except, I’ve edited the main theme…. I want to do the same thing, inserting the same line, but via child themes.

    I don’t know if it’s possible, but in keeping with best practices I don’t simply want to override the parent footer.php just in case a future theme update edited the footer.php file…

    Is this possible via functions.php?

    I hope that makes sense…

    TL;DR I want to add a specific line of php/code into a specific div of a theme using child themes rather than editing the parent.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You should be able to copy footer.php from the parent theme to the child theme and edit the child theme’s copy. WordPress will use any files from the child theme’s folder first and fall back to the parent theme’s files if necessary.

    Thread Starter Omorgan

    (@omorgan)

    Hi,

    Surely the issue with that is that if, at somepoint in the future, the theme designer added different code to the theme thay did some fantastic new thing in an update, I wouldnt even know of its existence/would need to update the child theme’s footer.php to accomodate.

    Surely that defeats the point?

    I know my example is tedious, but imagine if i were trying to edit something grander in the parent theme, something where the theme designer may tweak…

    Owen.

    Well, based on the code you’ve shown, I don’t see any other way to accomplish what you’re trying to do other than editing footer.php directly. Does your theme have any built-in options to change the footer text?

    As for “the point”, one thing to consider is that if you edited the parent’s files directly, there would be no way to avoid having to reapply your changes the next time the theme updated anyway, and if you were editing something grander, you might not fully remember all the changes you made. If you had a child theme in place, your changes would still exist in their own folder and you could compare the code to see if any major changes had happened that you would want to incorporate into the child theme.

    Thread Starter Omorgan

    (@omorgan)

    Hi,

    Thanks for your swift replies ??

    After doing the research, I thought as much, but your clarification is really appreciated!

    Thank you for your time and support!

    Thanks,

    Owen.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add text/code to footer.php via child theme’ is closed to new replies.