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

Create hooks based on an array of hook names?

Your proposal is OK – you can see this in action even in the WordPress itself. See admin-ajax.php where you can find this piece of code: // Register core Ajax calls. if ( ! empty( $_GET[‘action’] ) && in_array( $_GET[‘action’], $core_actions_get ) ) add_action( ‘wp_ajax_’ . $_GET[‘action’], ‘wp_ajax_’ . str_replace( ‘-‘, ‘_’, $_GET[‘action’] ), 1 … Read more

Pros and cons of actions over shortcodes

Neither are correct. Just use show_foo(): <?php echo show_foo(); ?> The only reason to ever use shortcodes is to insert dynamic content into a page or post from within the editor (Although, these days the ‘proper’ way to do that would be with a block, although that’s more difficult). Shortcodes should not be used for … Read more

What would cause the ‘wp’ action to fire twice per page (but only once per post) in Firefox only?

Check the source for your page. I’m guessing that your source code includes a <link rel=”next”> in the header, as WordPress injects by default, and Firefox is prefetching the “next” page in order to cache it. Try this to remove that link from your header: remove_action(‘wp_head’, ‘adjacent_posts_rel_link_wp_head’); Found this blog with more details: WordPress rel=”next” … Read more

Remove action within a class in a parent theme from the child theme

To remove an action or filter, the function/method name and the priority must match with the previously added action/filter. The action you want to remove is added with a priority of 10 (default value) while you are trying to remove the action with priority of 99. Try this: remove_action( ‘woocommerce_product_options_inventory_product_data’, array( ‘Electro_WC_Helper’, ‘product_options_inventory_product_data’ ) ); … Read more

add action which returns modified value

The things you can change in there are: $secure_cookie = apply_filters(‘secure_signon_cookie’, $secure_cookie, $credentials); Cookie The $credentials for the user_login and user_password1) Example add_action( ‘wp_authenticate’, ‘wpse119273UserCredentials’ ); function wpse119273UserCredentials( $credentials ) { // Make sure to secure that value $credentials[‘user_password’] = ‘foo’; } To generate a secure password, take a look at the function wp_generate_password() and … Read more

Apply the_title filter to post titles AND backend auto social-sharing plugin, but not nav menu

Solution function append_album_review_to_title( $title, $id = NULL ) { if ($id) { if ( get_post_type( $id ) == ‘album_review’ ){ return ‘Album Review: ‘ . $title; } else { return $title; } } else { return ‘Album Review: ‘ . $title; }; } add_filter(‘the_title’, ‘append_album_review_to_title’, 10, 2); Explanation First trying this: function append_album_review_to_title( $title, $id … Read more

When is it too late to call the action wp_enqueue_scripts?

The function wp_enqueue_scripts— with an ‘s’– is used as a callback to wp_head. All that the function wp_enqueue_scripts does is fire the wp_enqueue_scripts action. So the last time that you would be able to use the action wp_enqueue_scripts is before the wp_enqueue_scripts callback on the wp_head hook. In terms of theme templates, that means you … Read more