I have a file in a plugin named form.php. I know that to make what I want to work I just need to change 1 line of code at $taxonomies = wp_dropdown_categories in this function below and add a parameter of depth => 1 into that line of code in this function.

private function taxonomy_select_field($field = array()) {
    if ( isset( $field['label'] ) ) {

    $this->output .= '<div class="ap-form-fields-in">';

    $taxonomies = wp_dropdown_categories( array( 
                'taxonomy'     => $field['taxonomy'],
                'orderby'      => @$field['orderby'],
                'hide_empty'   => 0,
                'hierarchical' => 1,
                'selected'     => @$field['value'],
                'name'         => @$field['name'],
                'class'        => 'ap-form-control',
                'id'           => @$field['name'],
                'echo'         => false
    ) );

    $this->output .= $taxonomies;


    if ( ! $this->field['show_desc_tip'] ) {

    $this->output .= '</div>';

But I do NOT want to be manually changing this line of code. How do I specifically override this using code snippets plugin or functions.php? with add_action or remove_action combination?

1 Answer 1


So you can't change code at random like this. If you need to change some behavior, then the plugin author needs to give you hooks - either filters or actions. If the plugin author didn't provide you with the right hooks, then you can't change the behavior, unfortunately.

You can see in the plugin code calls to do_action or apply_filters - those will tell you what kind of hooks the plugin developer put in place.

Your only "clean" options if you don't have access to hooks, are to:

  • ask the plugin author to allow some customization of the taxonomy used - she will decide how to best do this, through hooks or plugin settings, or...
  • write or hire someone to write your own plugin


So since this is open source code, what you can do is fork the code, and then make your modification in your own copy. Make sure to change the plugin's author and urls however, so you don't mistakingly update the plugin down the road and erase your changes!

Hope this helps!

  • Thanks. I'm new to this. I know it works if I change the code directly. How do I know if this is available with do_action or apply_filters? Do I just grep for that or is it in the same file? This is open source. The file is here - github.com/anspress/anspress/blob/… and its line 454 I'm trying to change.
    – Frank
    Jan 19, 2017 at 21:43
  • Right, so as I said, you'd want to look for do_action or apply_filters in the plugin's code, around the area where you want to do your change. Doesn't seem to be in this one though. However, if this is open source, available on github, that gives you another option - I've updated my answer.
    – nibnut
    Jan 19, 2017 at 21:51
  • Thanks. So if I fork the code then how do I get create and get the updated resulting zip file that would be associated with the plugin? Or what is the best way to get the forked code into my wordpress site.
    – Frank
    Jan 19, 2017 at 22:09
  • Once you have forked the repository, you can download your own copy and modify the source code. Then you can either upload the plugin folder to your website's wp-content/plugins directory, or zip your folder, and install it through WordPress' plugins "Add new" page.
    – nibnut
    Jan 19, 2017 at 22:51

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.