• Resolved grobs38

    (@grobs38)


    Hi,

    I’am currently trying to change the footer text.

    I read this forum topic but I don’t want to lose my custom text at every theme update so I tried to do it in a child theme.

    I tried to add this code in my child theme’s functions.php:

    <?php
    /**
     ** activation theme
     **/
    
    add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
    
    function theme_enqueue_styles() {
         wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    }
    
    /**
     * Footer credits
     */
    
    /*
    function oblique_footer_credits() {
        echo 'My custom text';
    }
    
    add_action( 'oblique_footer', 'oblique_footer_credits' );
    */
    
    ?>

    But it breaks the entire site because the parent theme already declares oblique_footer_credits().

    Could you please help?

    Thanks

Viewing 10 replies - 1 through 10 (of 10 total)
  • You can change the name of your function to something unique. For example:

    /**
     * Footer credits
     */
    
    function my_oblique_footer_credits() {
        echo 'My custom text';
    }
    
    add_action( 'oblique_footer', 'my_oblique_footer_credits' );

    Above I added my_ to the beginning of the function name and changed the second argument in the add_action to use the new function.

    Thread Starter grobs38

    (@grobs38)

    Hi jowaltham, thanks for your reply.

    I already tried this but instead of replacing the footer message, it adds it the custom one before the parent one.

    With your code, the footer becomes: “My custom textProudly powered by WordPress | Theme: Oblique by Themeisle.” instead of just “My custom text”.

    What have I to do to remove the parent footer?

    To remove the original function you need

    remove_action( 'oblique_footer', 'oblique_footer_credits' );

    This can be placed under the add_action( 'oblique_footer', 'my_oblique_footer_credits' ); line.

    Thread Starter grobs38

    (@grobs38)

    Thanks again jowaltham to take the time to help me ??

    I tried this snippet but it seems that nothing changed. The parent AND child’s footer messages are displayed.

    function custom_oblique_footer_credits() {
        echo 'My custom text';
    }
    
    add_action( 'oblique_footer', 'custom_oblique_footer_credits' );
    remove_action( 'oblique_footer', 'oblique_footer_credits' );

    As child theme’s function.php file is loaded before the parent, maybe that the remove_action function couldn’t work properly (parent’s function is not declared yet when remove_action is executed)?

    My apologies, I suggested something without testing first. Yes you are on the right track. What we need to do is add the remove action to a hook slightly earlier.

    I’ve tested this locally and it works for me:

    function custom_oblique_footer_credits() {
        echo 'My custom text';
    }
    add_action( 'oblique_footer', 'custom_oblique_footer_credits' );
    
    function remove_oblique_footer_credits() {
    	remove_action( 'oblique_footer', 'oblique_footer_credits' );
    }
    add_action( 'get_footer', 'remove_oblique_footer_credits');

    I’m using the earlier hook get_footer to run a function (remove_oblique_footer_credits) that then runs the remove_action on the oblique_footer hook.

    I hope that makes sense and works for you! Do let me know.

    Thanks
    Jo

    Thread Starter grobs38

    (@grobs38)

    Thanks a lot jowaltham, it now works like a charm!

    Alexandra

    (@alexandrastan001)

    Hi,

    Great! Glad that you got is solved and thank you @jowaltham for your help. ??
    We greatly appreciate it.

    Best regards,
    Alexandra

    I’m using oblique as a child-theme. Now I want to change the footer.php like this solution. But I don’t know, where I have to put this remove function in the footer.php.

    Here’s the original content of the copied footer.php from the parent-theme oblique:

    <?php
    /**
    * The template for displaying the footer.
    *
    * Contains the closing of the #content div and all content after
    *
    * @package Oblique
    */
    ?>

    </div>
    </div><!– #content –>

    <div class=”svg-container footer-svg svg-block”>
    <?php oblique_svg_1(); ?>
    </div>
    <footer id=”colophon” class=”site-footer” role=”contentinfo”>
    <div class=”site-info container”>
    <?php do_action( ‘oblique_footer’ ); ?>
    </div><!– .site-info –>
    </footer><!– #colophon –>
    </div><!– #page –>

    <?php wp_footer(); ?>

    </body>
    </html>

    Could you help me please? Thx a lot!

    I’ve solved it ??

    Hi cat4net,
    Do you have the full code for the new footer with the removed function?

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Replace footer in a child theme’ is closed to new replies.