Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you modify a WordPress theme class with a child theme?

I'm using a theme called "views base." Documentation is here: http://wp-types.com/documentation/views-inside/views-base-theme/views-base-customization/

I've created a child theme and I'm trying to figure out how to add a new widget area to the theme.

The parent theme's functions.php file has this line: require_once('class_base_theme.php');

This file contains a class called "class_base_theme" with a $sidebar_array property with an array of all the widget regions.

I can easily add in a new region in this parent class simply by adding it to the $sidebar_array property. But I can't figure out how to extend and modify this class in the child theme. I can't do it in my child theme's functions.php file because it is called before the parent's functions.php file.

like image 921
StevieD Avatar asked Jan 18 '26 21:01

StevieD


1 Answers

Actually, it depends on the parent theme. If the parent uses if (!class_exists('class_name')) before loading the class, then it'll work, but if not you're going to get an error trying to redeclare a class. I would suggest extending the class. Make a new php file in your theme, require it, then extend the parent's class that way like Child_Class extends Parent_Class {}

Now, from within your new class Child_Class you should be able to access $sidebar_array and do whatever you want with it, as well as use the parent's class functions, if needed.

like image 108
Tim Hallman Avatar answered Jan 20 '26 16:01

Tim Hallman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!