0

I'm trying to make a small modification to a custom widget that was included with a clients parent theme.

Whenever I remove the parents version of the widget (for testing purposes) the child version of the widget does not take over. Instead, the widget simply disappears.

I've mimicked the directory structure of the parent theme, copied my modified widget .php file into the proper location, and have included the following code in my child themes function.php:

include("../maxmag-child/widgets/widget-tabs.php");

Any idea why the child's version of the widget isn't available?

  • 1
    Show us how you have written the "child widget". Did you extend the parent class? – kaiser May 20 '13 at 20:29
  • Sorry, I'm not sure what you mean by "extend the parent class". The only edit I did to the widget was remove a div and it's contents. – JoshuaG May 20 '13 at 20:48
  • So you copy pasted the files contents, changed it slightly, uploaded it into a child theme sub folder and included it? – kaiser May 20 '13 at 21:04
  • Yes, that is correct. – JoshuaG May 20 '13 at 21:23
  • Then the same class is loaded twice. It's the same as defining a function twice: It doesn't work. – kaiser May 20 '13 at 22:50
1

Either go and extend the class, or copy, paste and rename it (not recommended).

class Child_Theme_Widget extends Parent_Theme_Widget
{
    // just re-define/override the parent theme widgets methods (functions) here
}
  • Sorry I'm not sure how to implement this. – JoshuaG May 20 '13 at 23:58
  • @user32576 You'll have to read the link to PHP.net and you need to learn some PHP (or get someone who does this for you). – kaiser May 21 '13 at 0:15
  • Okay, I'll take a look and see if I can piece it together. – JoshuaG May 21 '13 at 0:19
  • 2
    Thanks for your help, I used your suggestion to find a solution. Here's what I did: Registered a new widget function maxmag_tabs_load_widgets() { register_widget( 'maxmag_tabs_widget' ); register_widget( 'maxmag_tabs_child_widget'); } Use the extend function on my new widget class maxmag_tabs_child_widget extends maxmag_tabs_widget { } – JoshuaG May 21 '13 at 21:59
  • 1
    @JoshuaG Great that you found a solution! Hint: You can now tick the answer as solution (below the voting arrows on the left side of the question) and even edit the answer to reflect your solution (community edits are appreciated). Comments don't take line breaks - that's what questions and answers are for. – kaiser May 21 '13 at 23:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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