How can I modify footer when footer.php calls to another file?

I am trying to modify the footer of aTheme's Talon theme. I am using a child theme that works properly. How can I modify the footer when footer.php calls for a function that is in function-footer.php?

In footer.php, I have this, which I can modify in the child theme.

    footer id="colophon" class="site-footer" role="contentinfo"
    div class="container"
        div class="row"   
        ?php do_action('talon_footer'); ?
        /div
    /div
/footer

If I modify ?php do_action('talon_footer'); ?, the whole footer is gone.

The talon_footer action is found in themes/talon/inc/functions/functions-footer.php. This file contains 3 actions for the footer: sidebar, credits and menu:

/**
     * Footer sidebar
     */
    function talon_footer_sidebar() {
        if ( is_active_sidebar( 'footer-1' ) ) {
            get_sidebar('footer');      
        }
    }
    add_action('talon_footer', 'talon_footer_sidebar', 7);

    /**
     * Footer credits
     */
    function talon_footer_credits() {
        ?
            div class="site-info col-md-6"
                a href="?php echo esc_url( __(                'https://wordpress.org/', 'talon' ) ); ?" rel="nofollow"?php printf(         esc_html__( 'Powered by %s', 'talon' ), 'WordPress' ); ?/a
                span class="sep" | /span
                ?php printf( esc_html__( 'Theme: %2$s by %1$s.', 'talon'       ), 'aThemes', 'a href="//athemes.com/theme/talon" rel="designer"Talon/a'        ); ?
            /div!-- .site-info --
        ?php
    }
    add_action('talon_footer', 'talon_footer_credits', 8);

    /**
     * Footer menu
     */
    function talon_footer_menu() {
        ?
            nav id="footer-navigation" class="footer-navigation col-md-        6" role="navigation"
                ?php wp_nav_menu( array( 'theme_location' = 'footer',         'menu_id' = 'footer-menu', 'depth' = 1 ) ); ?
            /nav
        ?php
    }
    add_action('talon_footer', 'talon_footer_menu', 9);

The themes/talon/inc/functions/ folder also contains loader.php which calls for the functions-footer.php file:

require get_template_directory() . '/inc/functions/functions-footer.php';

I want to modify it in the child theme.

I have tried to:

  • add functions-footer.php to the child theme with the proper path
  • add loader.php to the child theme with the proper path and modify the path in the file

it still uses the one in the parent theme.

I have also tried to add require get_template_directory() . '/inc/functions/functions-footer.php'; to the child theme's funtion.php, it tells me the function cannot be declared twice.

If I add one of the functions from functions-footer.php to the child theme's function.php, it breaks the code and returns a white page.

I have worked around it by duplicating the functions I want to modify in the child theme's function.php with a different name and a different class and using css display:none on the original one, but it's not ideal. A php method would be much cleaner.

Thanks in advance!

Topic function-exists functions php Wordpress

Category Web


You can remove_action and add_action with your own action. (https://codex.wordpress.org/Function_Reference/remove_action) In your child theme functions.php you can add this code for example :

add_action('init', 'remove_talon_footer'); // Remove your parent theme actions
function remove_talon_footer() {
    remove_action('talon_footer', 'talon_footer_sidebar', 7); // Use same priority
    remove_action('talon_footer', 'talon_footer_credits', 8);
    remove_action('talon_footer', 'talon_footer_menu', 9);
}

/**
 * Footer sidebar
 */
function my_talon_footer_menu() {
    // What you want
}
add_action('talon_footer', 'my_talon_footer_sidebar', 7);

/**
 * Footer credits
 */
function my_talon_footer_menu() {
    // What you want
}
add_action('talon_footer', 'my_talon_footer_credits', 8);

/**
 * Footer menu
 */
function my_talon_footer_menu() {
    // What you want
}
add_action('talon_footer', 'my_talon_footer_menu', 9);

The first function is here to tell WP to remove the action in your parent theme, the others can be placed in a footer functions file.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.