WordPress Icon Logo
me@grafxflow

Written by me@grafxflow

01 Sep, 2012

2

2,021

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').

Add comment

2 Response

    Finch
    07 Dec 2013

    You saved my life man!! Thanks a lot!!

    |

    me@grafxflow
    07 Dec 2013

    Glad to help.

Smart Search

133 Following
50 Followers

me@grafxflow

Hull, United Kingdom

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!

Follow