Action hook with wrapper html

You want the has_action() function. add_action( ‘category_promo_header’, function () { echo ‘hi there’; } ); if (has_action(‘category_promo_header’)) { echo ‘<div>’; do_action(‘category_promo_header’); echo ‘</div>’; } Comment that add_action and you should see that nothing is printed at all.

add_action to wp_head is added, but not called

Can we think litter bit different way: add_action(‘wp_head’,’new_wp_head’); function new_wp_head() { echo “calling wp_head”; global $civicrm_root; if ( empty( $civicrm_root ) ) { return; } $region = CRM_Core_Region::instance(‘html-header’, FALSE); if ( $region ) { echo ‘<!– CiviCRM html header –>’; echo $region->render( ” ); } } Make sure in which file you put this and … Read more

Use add_action within template

There is no limitation to using add_action(), except that core must have it loaded already. Practically this means pretty much anywhere, but wp-config.php. While it is possible to do it in template, it’s not a common practice because of: Timing issues (your template part might be loaded after the hooks you need). Code base clarity … Read more

wp_ajax action is not run when ajax trigger

I’ve tested your code and it works perfectly. I’ve just declared the dependencies for the JavaScript, so it is loaded correctly after jQuery. This is how I’ve tested it: functions.php function my_resource() { wp_enqueue_script(‘my-jquery’,get_template_directory_uri().’/jqfunctions.js’, array(‘jquery’)); wp_localize_script( ‘my-jquery’, ‘myback’, array(‘ajax_url’ => admin_url( ‘admin-ajax.php’ ))); } add_action(‘wp_enqueue_scripts’, ‘my_resource’); function getsomething(){ wp_send_json_error(‘hey’); } add_action(‘wp_ajax_nopriv_getsomething’, ‘getsomething’); add_action(‘wp_ajax_getsomething’, ‘getsomething’); jqfunctions.js … Read more