0

I'd like to remove the "Powered by Wordpress" custom link in the footer.

I want to do this using action hooks/filters in the child theme's function.php file.

I don't want to use CSS (which just hides it), edit the original theme file (which will get overriden when the theme updates), or copy the footer.php file to the child theme and edit it out there (since I will then have to update the file after a theme update).

The theme I'm using is 'sparkling'. The footer info function is defined in the extras.php file:

function sparkling_footer_info() {
global $sparkling_footer_info;
printf( esc_html__( 'Theme by %1$s Powered by %2$s', 'sparkling' ) , '<a href="http://colorlib.com/" target="_blank">Colorlib</a>', '<a href="http://wordpress.org/" target="_blank">WordPress</a>');
}

And called in the footer.php file (a few lines from the bottom):

<div id="footer-area">
    <div class="container footer-inner">
        <div class="row">
            <?php get_sidebar( 'footer' ); ?>
        </div>
    </div>

    <footer id="colophon" class="site-footer" role="contentinfo">
        <div class="site-info container">
            <div class="row">
                <?php if( of_get_option('footer_social') ) sparkling_social_icons(); ?>
                <nav role="navigation" class="col-md-6">
                    <?php sparkling_footer_links(); ?>
                </nav>
                <div class="copyright col-md-6">
                    <?php echo of_get_option( 'custom_footer_text', 'sparkling' ); ?>
                    <?php sparkling_footer_info(); ?>
                </div>
            </div>
        </div><!-- .site-info -->
        <div class="scroll-to-top"><i class="fa fa-angle-up"></i></div><!-- .scroll-to-top -->
    </footer><!-- #colophon -->
</div>

I tried inserting the following into the child's function.php (together with a few variants), but it doesn't work:

function remove_sparkling_footer(){
    remove_action( 'wp_footer', 'sparkling_footer_info' );}
add_action( 'init', 'remove_sparkling_footer' );

Any help or ideas would be greatly appreciated.

closed as off-topic by jgraup, cjbj, bueltge, kaiser Nov 19 '16 at 0:20

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • It's already described how to change the footer copyright in the Sparkling Theme Documentation. – Max Yudin Nov 11 '16 at 11:16
  • @MaxYudin: that gives the option to either add text to the footer, or to modify the existing text in terms of html markup (e.g. using the <b> tag), but it doesn't give the option to remove the "Powered by..." text, which is what I'm trying to do. – Thredolsen Nov 11 '16 at 13:16
  • The only option you have is to copy the footer.php to a child theme and modify it there as it is a plain function call. If you want to have a more eloquent way, ask the developer to use a hook or filter instead. – kaiser Nov 19 '16 at 0:20
1

As the function sparkling_footer_info() uses esc_html__() and this function runs the esc_html filter before outputting, you can intercept the output there.

add_filter ('esc_html', 'wpse_245817_esc_html', 100, 2 );
function wpse_245817_esc_html( $safe_text, $text ) {
    if ( $safe_text == 'Theme by %1$s Powered by %2$s' ) {
        return '';
    }
    return $safe_text;
}

Maybe you have to adapt the code a little for your own needs, I didn't test it either.

  • This worked, but it broke a bunch of other things (i.e. header text is not displayed, site tagline in the tab is not displayed). Any ideas on making it more restrictive? (Also, note that a closing parenthesis is missing after 'Theme by'). Thank you. – Thredolsen Nov 13 '16 at 14:17
  • @Thredolsen Actually the missing parenthesis was to be put at another position. I edited that. This was probably also the reason for it breaking other things. – JHoffmann Nov 13 '16 at 21:30
  • Tried it, still same issue as before (it works but breaks other things such as the header text). – Thredolsen Nov 14 '16 at 8:14
  • @Thredolsen Ok, I had forgotten to add the retrun statement for when the condition is not met. – JHoffmann Nov 14 '16 at 9:42
  • @ JHoffmann now nothing breaks, but it doesn't filter out the output either (The "Powered by..." text). Also a small clarification in case I didn't explain myself right: what I originally intended was to remove the entire output there ('Theme by %1$s Powered by %2$s') . – Thredolsen Nov 14 '16 at 10:56
0

The function sparkling_footer_info() is directly called from the footer code, without any action or filter you could intercept. There's no filter inside the function either. Presumably the people at Sparkling don't want you to remove it. There might even be something about this in de theme's license, so check if what you are trying to do is legal.

That said, PHP offers a method to redefine functions (provided runkit is included in your PHP install, which isn't automatically the case). You cannot remove the function unless you remove it from the template call in your child theme, which apparently is not what you want. So you redefine it with an empty function (that simply says 'return').

You shuld run the redefinition after sparkling_footer_info() has been loaded, which is after your child theme's functions.php has been loaded. You could, for instance, attach it to wp_head like this:

add_action ('wp_head','wpse245817_replace_function');

function wpse245817_replace_function () {
  runkit_function_redefine('sparkling_footer_info','','return;');
  }

Please note that I haven't tested this code. Some debugging may be necessary.

  • Tried it, and it doesn't work. I get the following output on the website: "Call to undefined function runkit_function_redefine() in home/file/location... on line 10. This is after debugging as suggested ("function wpse245817_replace_function" should be followed directly by "()"). – Thredolsen Nov 11 '16 at 20:43
  • @Thredolsen It means runkit isn't included on your hosts PHP install. If you have access to the server you could try installing it yourself. There are alternatives, like Patchwork, but I have no experience with that. I've changed my answer to note this. – cjbj Nov 12 '16 at 11:12

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