WordPress parent theme usually defines an action that calls a function. You wrap that function in function_exists() so that you can overwrite it in a child theme.
add_filter('the_title', 'markdown_title');
if ( ! function_exists('markdown_title')) {
function markdown_title($post_title) {}
}
The Child theme simply sets a new function markdown_title()
Alternatively, you use OOP in the parent theme and then namespace everything nicely but are now you are using composer autoload in your parent theme and as well as your child theme creating another namespace for that theme and extending parent classes to adjust parent method functionality.
I have not tried this yet, and not many “developer” themes cover this. But because it is namespaced and the scope of the actions and filters are typical $this or the namespace of another class. I would have to use __construct to register the actions which then presumably extend, call parent::__construct(); and hopefully the WordPress actions do their job and use the new method from the child theme.
namespace ParentTheme;
class myClass
{
public function __construct()
{
add_filter('the_title', [$this, 'markdown_title']);
}
public function markdown_title($post_title)
{
// Make Markdown
}
}
namespace ChildTheme;
class anotherClass extends myClass {
public function __construct()
{
parent::__construct();
}
public function markdown_title($post_title)
{
// Make Awesome Markdown
}
}
Actually, now that I look at this, I have no idea if it would work.
WordPress parent theme usually defines an action that calls a function. You wrap that function in
function_exists()so that you can overwrite it in a child theme.The Child theme simply sets a new function
markdown_title()Alternatively, you use OOP in the parent theme and then namespace everything nicely but are now you are using composer autoload in your parent theme and as well as your child theme creating another namespace for that theme and extending parent classes to adjust parent method functionality.
I have not tried this yet, and not many “developer” themes cover this. But because it is namespaced and the scope of the actions and filters are typical
$thisor the namespace of another class. I would have to use__constructto register the actions which then presumably extend, callparent::__construct();and hopefully the WordPress actions do their job and use the new method from the child theme.Actually, now that I look at this, I have no idea if it would work.