Is it possible to add an action hook via wp_localize_script
, so I can position where I want the hook to run in HTML markup that is made in the JavaScript?
So something like:
$data = array (
'ng_slicknav' => array(
'ng_slicksearch' => home_url( '/' ),
'ng_slicknav_closedsymbol' => esc_html( $options['ng_slicknav_closedsymbol'] ),
'ng_slicknav_hook' => do_action( 'myplugin_after_hook' ),
),
);
// Add filter
$data = apply_filters( 'ng_slicknav_slickNavVars', $data );
// Pass PHP variables to jQuery script
wp_localize_script( 'slicknav-init', 'slickNavVars', $data );
wp_enqueue_script( 'slicknav-init' );
The variable I am trying to add is ng_slicknav_hook
, but anything I hook to it falls just outside of the HTML markup in JavaScript; it doesn’t honor the position I put it in.