Articles of actions

How to get list of all hooks of current theme / plugin?

I want to get the list of all available hooks from active theme / from a specific plugin. I was tried to get it from global variables $wp_actions & $wp_filter But, They are showing all registered hooks. E.g. global $wp_actions, $wp_filter; echo ‘<pre>’; print_r($wp_filter); E.g. If theme or plugin register the action in after_setup_theme then […]

remove_action not working with procedural function

I have a purchased theme that procedurally loads an action like this: function func() { echo “head content”; } add_action( ‘wp_head’, ‘func’, 5 ); Following the remove action codex I tried the following: remove_action( ‘wp_head’, ‘func’, 5 ); Which did not work so I figured it was a priority issue so I adjusted both higher […]

Performance : Duplicating `add_action`

If was wondering about PHP performance on WordPress, If I had many duplicate add_action. add_action( ‘init’, ‘func_a’ ); add_action( ‘init’, ‘func_b’ ); add_action( ‘init’, ‘func_c’ ); //… so on vs add_action( ‘init’, ‘func_init’ ); function func_init() { function_a(); function_b(); function_c(); //… so on } The first one should be a problem with performance if I […]

Reuse variable in hook callback

I’m setting up a child theme in WordPress and I can’t make add_action to be fired within functions.php. Functions.php is called and I can run code from within. Any idea on what I’m doing wrong? $debug_msg = “Hi there!”; function test_function() { error_log($debug_msg, 0); } add_action(‘init’, ‘test_function’, 20);

Which action hook to use for function?

I’ve created a custom category template to display the current category’s child categories instead of posts. Child categories are displayed via a custom thumbnail, title and category description. I have added a function to trim the category description to a predefined number of characters, but I’m not sure which action hook to use. Here’s the […]

How to remove function?

I’m trying to remove a function that is defined in my parent theme but can’t get it to work. The function I want to remove prints previous/next post navigation. Here’s the function: add_action( ‘generate_after_entry_content’, ‘generate_footer_meta’ ); function generate_footer_meta() { if ( ‘post’ == get_post_type() ) : ?> <footer class=”entry-meta”> <?php generate_entry_meta(); ?> <?php if ( […]

Pass parameters to function through an action

I’m trying to pass the value of a variable into do_action and then use it in the resulting function but it’s not working. The action is being fired in the woocommerce checkout, so it also passes the $checkout variable as well, which is working fine. Simplified example below: add_action( ‘my_action’, ‘my_function’ ); function my_function( $checkout, […]

register_taxonomy and register_post_type does not work

I have a problem using the register_post_type and register_taxonomy on my WordPress. I created the code on my functions.php and it does not update my panel. Why? //Categorias personalizadas register_taxonomy(‘produtos’, ‘produto’, array(‘hierarchical’ => true, ‘label’ => ‘Categorias de Produtos’, ‘query_var’ => true, ‘rewrite’ => true)); //Posts personalizados add_action(‘init’, ‘create_post_type’); function create_post_type() { register_post_type(‘produto’, array( ‘labels’ […]

Which are the hooks run before/after when a category's deletion?

What are the actions that a plugin can hook on to for processing when the user deletes a category?

How to generate numbers indistinguishable for the IDs of the posts

For a few days I’ve been after a filter or a function that creates more random ID’s for posts like: 1920363522091 or Hpw_027991m-q Instead of the wordpress pattern that is: 1, 2, 3, 4 … It can be in sequence too, but starting with a very high number that with time becomes indistinguishable. I researched […]