Blog

01 Sep
2012

WordPress Icon Logo

Embed Javascript or CSS in specific pages in WordPress


Normally if you wanted to include a custom javascript or css in your WordPress theme, you would edit the header.php in the WordPress admin.

Appearance/Editor and choose Header (header.php)

But lets say you only wanted it to be included on a specific page, well again edit the header.php file and you need to add the following based on the page being called 'video'.

For javascript:

<?php if (is_page('video') ) { ?>
    <!-- Embed custom javascript -->
    <script type='text/javascript' src="<?php bloginfo('template_directory'); ?>/js/javascript_custom.js"></script>
<?php } ?>

For CSS:

<?php if (is_page('video') ) { ?>
    <!-- Embed custom CSS -->
    <link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/css/css_custom.css" media="screen" />
<?php } ?>

A quick note... you can also use the post/pages id number if (is_page('12').

Tagged: < css | embed | javascript | wordpress >
Posted in: < CMS >
me@grafxflow avatar

me@grafxflow


I am a Full-stack Developer who also started delving into the world of UX/UI Design a few years back. I blog and tweet to hopefully share a little bit of knowledge that can help others around the web. Thanks for stopping by!

Visitors also viewed these posts

2 Thoughts

  1. 07 Dec
    2013

    avatar

    Finch

    You saved my life man!! Thanks a lot!!
  2. 07 Dec
    2013

    avatar

    me@grafxflow

    Glad to help.

Add comment

Add comment