add_action taking an array with the 2nd argument?

Shouldn’t the 2nd argument be a function? The second argument should be a value of type callable. callables are a fundamental type in PHP. E.g. these are some valid callables: Value Equivalent ‘test’ test() [ $obj, ‘test’ ] $obj->test() [ ‘foo’, ‘bar’ ] foo::bar() function() {…} or closure $foo = function(){…}; $foo(); And so on, … Read more

What action hook can I use to add a JavaScript to a page post using a theme template that is not including get_header() nor get_footer()?

Completely skipping wp_head and wp_footer doesn’t seem like a good idea, many core components and plugins depend on these hooks. Instead, you could create a light header and footer, and load them via an extra argument to get_header() and get_footer(). get_header( ‘light’ ) will load header-light.php instead of the regular header file. Create one without … Read more

do add_action on condition

Use has_category() to check if a post belongs to a certain category. function email_friends( $post_ID ) { if ( has_category( ‘uncategorized’, $post_ID ) { $friends=”[email protected], [email protected]”; wp_mail( $friends, “sally’s blog updated”, ‘I just put something on my blog: ‘ . get_permalink( $post_ID ) ); } } add_action(‘publish_post’, ’email_friends’); And you don’t need to return anything … Read more

Trying to get custom js files in my admin header

Ahh ok I figured it out while researching. I needed to add the $hook parameter and pass it to my function like so: function my_admin_enqueue_scripts($hook) { global $current_screen; if ( ‘post.php’ != $hook ) return; wp_register_script(‘my-scripts’, get_template_directory_uri() . ‘/js/custom/my-scripts.js’ ); wp_enqueue_script(‘my-scripts’); wp_localize_script(‘my-scripts’, ‘wp_ajax’, array( ‘ajaxurl’ => admin_url( ‘admin-ajax.php’ ))); } This gave me the results … Read more