WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a javascript file and a corresponding css file. Both files should be embedded at a single wordpress page. I managed to load the javascript file, but how can a css file be loaded from/at a page?

share|improve this question
I asked this same question regarding a stylesheet just recently, I unknowingly included fully-functional code in my question you can use. Adding the script file would be very simple from there using the wp_register_script() function and wp_enqueue_script action hook as mentioned before. wordpress.stackexchange.com/questions/39130/… – Evan Mattson Jan 23 '12 at 1:56

You should be doing JS and CSS loading with wp_enequeue_script and wp_enqueue_style. Register the script at the init hook (or later) and then enquque it at the wp_print_scripts hook. Using this, you can say something like if( is_page( 42 ) ) : wp_enqueue_script( 'my_script' ); endif; and just call it a day.

Additional Functions: wp_register_script(), wp_register_style

share|improve this answer
Thanks for the hint! Would it be save/advisable to call wp_enqueue_... within php code that is placed in the content of the page and executed by Exec-PHP plugin? <wordpress.org/extend/plugins/exec-php/>; – Davos Seaworth Jan 22 '12 at 20:38
You should avoid modifying plugins and core files as this will cause your modifications to be removed and potentially break should the file you modified be updated. The correct way to do this is to register and enqueue the files in your theme's function.php file (or your own custom plugin if you're using a theme that's not yours). – mor7ifer Jan 22 '12 at 20:46

How about this? have a new page template, then put the Header in this page, then you can load a different CSS file.

it's not a smart way to do it,i know :(

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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