• I would like to add javascript to a single post custom template (doing the single post template, etc, is already done).

    I don’t want to add javascript to my functions because I don’t want to add it to the page load. My site doesn’t use javascript in general.

    However, I want to display some javascript (an API for a type of Google Map tracker) on one of my posts. I don’t know how to do this, and I’ve tried various ways.

    I think I need to add javascript in a js folder and load it, but I would like to know how to either A) load it right from my custom single page without adding it to a functions.php at all, or B) on my custom single, load a secondary functions.php and load my javascript though that.

    If anyone has an even better solution, I’m open to that, too (trying to avoid plugins though as much as possible).

    Thanks

Viewing 1 replies (of 1 total)
  • Why not just add this to your functions file?

    function your_function() {
    $postid = get_the_ID();
     if ( $postid = 55 ) {
       echo 'insert javascript here';
     }
    }
    add_action('wp_head', 'your_function');

    This will check for the appropriate post ID (I’ve chosen 55 as an example) and if it’s that post, it will echo the JavaScript into the <head> of that post.

    (Alternately, if it’s a lot of JavaScript, you can add it to a separate file and enqueue the file instead of echoing the JS.)

Viewing 1 replies (of 1 total)
  • The topic ‘Add a second functions.php or insert functions into custom single template?’ is closed to new replies.