top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

How to override function in parent theme via child theme function in Wordpress?

0 votes
45 views

I am trying to do override a function which is inside a class in the parent theme via child theme function. Can someone give me the correct way to override parent theme function via child theme function? Is it even possible on a non pluggable class?

The class itself extends from another class and the base class is pluggable.

class Fre_ReviewAction extends AE_Base --> Class attempting to overrite
----------------------------------
if (!class_exists('AE_Base')) {
class AE_Base --> Base class IS PLUGGABLE?
posted May 31, 2017 by Avijit Maity

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Yes you can do that , first you need to remove the action which you have used in the parent/base class.

function remove_add_class_actions() {
  //remove some action stuff , for example I used woocommerce action
  remove_action( 'some_action_hook', array( $GLOBALS['someglobals'], 'functiontooverrideinchildclass' ), 10, 3 );

  //add action by child class m in your case it will be Fre_ReviewAction
  add_action( 'some_action_hook', array(  new Fre_ReviewAction, 'functiontooverrideinchildclass' ) );
}
add_action( 'init','remove_add_class_actions' );

After that you need define the child class extending parent,

class Fre_ReviewAction extends AE_Base {
  function __construct() {
    //parent::__construct();
  }
  function functiontooverrideinchildclass(){
    //your stuff here
  }
}
answer Jun 7, 2017 by Ajoy Garang
Similar Questions
0 votes

I just created a custom theme for my wordpress project inside my wp-content/themes/mycustomtheme, I added an index.php and a style.css file to the new theme but when I go to themes in my dashboard the newly created theme is not shown as an option. What else am I missing? Can anybody help me?
This is my style.css

/*
Theme Name: Start WordPress
Theme URI: http://wordpress.org/themes/startwordpress
Author: Me
Author URI: http://wordpress.org/
Description: The Start WordPress theme is my first custom theme.
Version: 1.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: bootstrap, black, brown, orange, tan, white, yellow, light, one-
column, two-columns, right-sidebar, flexible-width, custom-header, 
custom-menu, editor-style, featured-images, microformats, post-
formats, rtl-language-support, sticky-post, translation-ready
Text Domain: startwordpress

This theme, like WordPress, is licensed under the GPL .
Use it to make something cool, have fun, and share what you've learned   
with others.
*/
0 votes

I try to get wordpress list categories with count at the end of each category's name by input the parent category as output.

Ex: I have a parent category name "alpha", and its child categories name are, Category A, Category B, Category C, Category D

I want the output display:

-Category A (5)

-Category B (2)

-Category C (6)

-Category D (7)

<?php
    $variable = wp_list_categories( array(
    'show_count' => true,
    'orderby'    => 'name',
    'style'      => 'none'
    ) );
    echo $variable; 
?>

The result of the above code display categories with the count of posts at the end, but it display all categories. Can anybody help me how I fix this problem?

0 votes

I want to change a role in my wordpress plugin.

if ( is_admin() && ! is_user_logged_in() && ! defined( 'DOING_AJAX' ) && $pagenow !== 'admin-post.php' ) {
            wp_die( __( 'This has been disabled', 'wp-hide-login' ), 403 );
        }

        $request = parse_url( $_SERVER['REQUEST_URI'] );

When my plugin get the action, Wordpress shows "This has been disabled" under WP default (admin-post.php) page. But I need when my function get assign it's redirect to 404 page.

As like as "This has been disabled" > http://www.example.com/404

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...