• So basically I have a js script that I want to display only when a post has a custom field applied to it.

    So lets say the script is this.js

    and the custom field I used for the post i used is Trav

    I put this php code into my header.php

    <?php if ( get_post_meta($post->ID, 'Trav', true))
    { ?>
    <script src="this.js"></script>
    <?php } ?>

    But then what happens is it applies to all my pages and it display all the time whether I’m in the homepage not just when I am in the post with the custom field.

  • The topic ‘Using custom fields to display a script in header’ is closed to new replies.