i am using genesis framework and types plugin. i create post meta fields for a custom post type name 'jobs' post meta fields for jobs CPT

i want to run a custom javascript named jobpostingschema.js in wp_head if post type is jobs enter image description here


You shouldn't do it in a shortcode, you should enqueue this particular JavaScript file only for the page you want. Place something like this in your functions.php:

function my_custom_scripts() {
    if( is_singular('job') ){
      wp_enqueue_script('jobpostingschema', get_stylesheet_directory_uri() . '/js/jobpostingschema.js', array(), '', false);
add_action('wp_enqueue_scripts', 'my_custom_scripts');
  • How can I add this script files to the very top in the wp_head?
    – Rana Waqar
    Oct 15 '18 at 14:05
  • With the above function. You can add an extra 'priority' parameter to add_action, for instance add_action('wp_enqueue_scripts', 'my_custom_scripts', 10), to determine the order in which it is added to the header.
    – Pim
    Oct 15 '18 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.