How To Make Sure That My Action Hook Executes Last
You define priority. It’s not a hack. Maybe it’s that you’re looking for is PHP_INT_MAX which is a PHP constant. So you can put it as priority number.
You define priority. It’s not a hack. Maybe it’s that you’re looking for is PHP_INT_MAX which is a PHP constant. So you can put it as priority number.
The accepted arguments value is used by WordPress as $length argument for array_slice when performing the action. It means that, yes, if you pass 0 no argument will be passed to your callback. However, you should care of that only if your function acts differently if an argument is passed or not. A function like … Read more
If you use do_action( ‘woo_collections_menu’ ); in the template, then your function must echo its value. Otherwise, you are returning the data into a black hole, nothing is outputting what you’re returning. If you use a filter, then you should return the value. The point of a filter is to take a value, filter that … Read more
Use the use keyword: $title = $instance[‘title’]; add_action( ‘wp_footer’, function() use ( $title ) { echo $title; });
No, you cannot do that, unfortunately, because get_header( $name ) doesn’t have a filter for the $name (it only passes the name with the action call). However, if you are willing to modify the header.php file for each site with something like this right at the beginning of the file: <?php if ( apply_filters( ‘load_custom_header’, … Read more
I just skimmed through the WPSEO_Frontend class and found the wpseo_robots filter for the meta robots content string. You might try something like: add_filter( ‘wpseo_robots’, function( $content ) { // your logic here … return $content; } ); to override the robots meta content from that plugin. ps: You should consider moving the add_action out … Read more
I would just set the post status for all posts for that particular category to private. If you already have a ton of posts, write yourself a small script using wp_update_post() to update all those posts’ post status to private. Any posts published after this you can then just set to private (in the publish … Read more
You have to use new_to_publish action as described on Post Status Transitions Codex page (updated according @prog comment): add_action( ‘new_to_publish’, ‘pms_post_published_notification’, 10, 1 ); function pms_post_published_notification( $post ) { if( ‘property’ === $post->post_type ) { // custom code here } } The only argument is passed to your function is $post object, so you can … Read more
Found the answer here: http://code.tutsplus.com/tutorials/a-guide-to-overriding-parent-theme-functions-in-your-child-theme–cms-22623 <?php function child_remove_parent_function() { remove_action( ‘woocommerce_before_main_content’, ‘mod_output_content_wrapper’, 10 ); } add_action( ‘wp_loaded’, ‘child_remove_parent_function’ ); ?> Explanation is in the link.
add_action() and add_filter() take 4 params: string $tag, callable $function_to_add, int $priority = 10, int $accepted_args = 1. So, the function you are hooking to takes more than 1 param, then just pass the number of params it accepts as the 4th param to add_action(). In your case, add_action (‘my_action’, ‘my_function’, 10, 2) ;