Use wc_enqueue_js only on specific pages – nested add_action

No idea why, but for the second snippet, changing the priority of the nested add_action from the default (10) to 20, causing the parent and child add_action to have a different priority solved the problem and now everything works perfectly: add_action( ‘template_redirect’, function() use ( $args ) { acau_enqueue_script ( $args ); }, 20); The … Read more

action init hook and get_post_types

Because you calling get_post_types() in functions.php that is excuted before ‘init’ action. Look this picture http://www.rarst.net/images/wordpress_core_load.png if you add an echo inside function test function test(){ $args = array( ‘public’ => true, ‘publicly_queryable’ => true, ‘show_ui’ => true, ‘query_var’ => true, ‘exclude_from_search’ => true, ‘hierarchical’ => false, ‘has_archive’ => false, ); register_post_type( ‘test’, $args ); … Read more

prevent post submission

See the Codex, on save_post. In answer to Question 1, it is fired whenever WordPress auto_saves a revision (i.e. hence when a post is edited). In particular, when creating a new post, wp-admin/post-new.php is loaded. WordPress then creates an auto draft even if you haven’t saved a draft or published to post. This is intended … Read more

I don’t understand why I need a lower priority to remove an action with a higher priority to make it work

You’re misunderstanding how priority works here somewhat. The priority determines the order that the functions run for a given hook, eg. genesis_entry_header. Priority is not global. When removing an action from a hook you need to use the same priority that the action was originally hooked with. Which you’re doing. You’re adding the action at … Read more

How to remove an action added by a child theme of Genesis

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 … Read more

Display different number of posts from one category on the different pages

You can check for the existence of a variable, so you don’t overwrite it: add_action( ‘pre_get_posts’, ‘wpse7262_pre_get_posts’ ); function wpse7262_pre_get_posts( &$wp_query ) { if ( $wp_query->is_category() ) { if ( ! array_key_exists( ‘post_type’, $wp_query->query_vars ) ) { $wp_query->set( ‘post_type’, ‘game’ ); } if ( ! array_key_exists( ‘posts_per_page’, $wp_query->query_vars ) ) { $wp_query->set( ‘posts_per_page’, 9 ); … Read more

Prevent function from triggering again when post in specific category gets another category?

We can utilize the add_term_relationship action to check if the current post is already assigned as popular. add_term_relationship fires before a term is inserted. I also think that you are using the wrong hook here to send your mail on. added_term_relationship fires quite early before any error checking. You can still encounter a failure after … Read more

Odd behaviour with submenu link creation

On the same page in codex you have this : NOTE: If you’re running into the “You do not have sufficient permissions to access this page.” message in a wp_die() screen, then you’ve hooked too early. So it answers to you question partly. The second part, the following code should work : add_action(‘admin_menu’, ‘my_add_submenu’); function … Read more