0

I developed a child theme for Genesis that adds Bootstrap on top of it.

In the core of this child theme I edited the way the category is displayed in the post, putting it above the title.

Now, I'd like to remove the action again but it seems not working.

This is theory, below I write something more, with code.

PRACTICALLY

I have the file src/lib/post.php that adds the action shq_genestrap_post_meta_categories:

function shq_genestrap_post_meta_categories() {

    $filtered = apply_filters( 'shq_genestrap_post_meta_categories', '[post_categories]' );

    if ( false == trim( $filtered ) ) {
        return;
    }

    // Remove the label and commas
    $filtered = str_replace([__( 'Filed Under: ', 'genesis' ), ', '], '', $filtered);

    genesis_markup( [
        'open'    => '<p %s>',
        'close'   => '</p>',
        'content' => genesis_strip_p_tags( $filtered ),
        'context' => 'entry-meta-categories',
    ] );
}
add_filter( 'shq_genestrap_post_meta_categories', 'do_shortcode', 20 );
add_action( 'genesis_entry_header', 'shq_genestrap_post_meta_categories', 9 );
remove_action( 'genesis_after_post_content', 'genesis_post_meta' );

As you can see, I add my custom function genesis_post_meta and then I remove the Genesis action genesis_post_meta.

Now, from the file src/functions.php I'd like to remove the action shq_genestrap_post_meta_categories I added before:

remove_action( 'genesis_entry_header', 'shq_genestrap_post_meta_categories', 9 );

But this doesn't work.

WHY AM I DOING THIS

The final goal is to provide a Bootstrap on top Genesis, so, the files in src/lib should not be modified: this way, when I update the main repository, it is possible to update the child theme.

To further customize the child theme, instead, I want to use the file src/functions.php that is never updated on the repository.

Doing this, if someday I update the file src/lib/post.php it is sufficient to copy the files from the main repository into the customized version of the theme and all the other customizations done through the src/functions.php file will continue to work.

But, as told, I'm not able to remove actions set by the files in src/lib.

CONCLUSIONS AND QUESTION (AGAIN)

I add the action shq_genestrap_post_meta_categories in src/lib/post.php.

Then I'd like to remove the action shq_genestrap_post_meta_categories from the file src/functions.php but this doesn't work:

// src/function.php

remove_action( 'genesis_entry_header', 'shq_genestrap_post_meta_categories', 9 );

How can I remove the action added in src/lib/post.php from the file src/functions.php?

3
  • 2
    Are you removing the original action with the same priority level it was initially added with - and are you removing the original action before you are adding it back in?
    – C C
    Commented Sep 7, 2018 at 12:16
  • 1
    This helpful?
    – D. Dan
    Commented Sep 7, 2018 at 12:44
  • D. Dan, I found that post on Google and tried to use it but didn't work. Now, I retrying and works. It was a problem of priority. I'm going to open a new question because I really don't understand how does priority works: I had to use priority 8 to remove an action added with priority 9, so added after I remove it o.O
    – Aerendir
    Commented Sep 7, 2018 at 13:23

1 Answer 1

0

Thanks to Dan that commented with a useful post I found on Google but didn't read with the required attention, the solution is this:

function my_remove() {
    remove_action( 'genesis_entry_header', 'shq_genestrap_post_meta_categories', 9 );
}
add_action('genesis_entry_header', 'my_remove', 8);

Using priority 9 in add_action() doesn't work: I had to set a priority lower than the one used to add the action I'm going to remove.

Anyway, I don't understand why a lower priority works: it seems to be counterintuitive.

About this I opened another question: I don't understand why I need a lower priority to remove an action with a higher priority to make it work

Anyone willing to reply is welcome!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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