• I want to rewrite the next function of a Theme:

    function widget( $args, $instance )

    The function is originaly located in:

    wp-content/themes/attitude/library/widgets/attitude_widgets.php

    I create a Child Theme and I wrote functions.php with a function called “widget” (with differente code of the original) but WP execute the function of the father theme and not execute the function of the child theme.

    Does anybody know how to do that in the right way? A real example using a function with parameters will be appreciated.

Viewing 1 replies (of 1 total)
  • It’s not that easy unfortunately.

    The file in the child theme will only be found if it’s include()‘ed in the child theme’s functions.php file. The problem then becomes that when you do that you’ll have a conflict with the same function name in the parent theme, so you’ll get a fatal error and break your site completely.

    The “right” way to do it dpeends totally on how well the theme was written. It should either use a conditional statement around it’s functions, or it should include some or to filter or action that you can use to modify the output of that function.

    Unfortuantely most times these options just aren’t available. In that case I’d suggest that you copy that file into the child theme and set up a new widget using the same function with a slightly different name, and use that as an additional widget.

Viewing 1 replies (of 1 total)
  • The topic ‘Modifying a function of a Theme’ is closed to new replies.