0

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?

1

2 Answers 2

2

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

2
  • 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> Commented Jan 22, 2012 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
    Commented Jan 22, 2012 at 20:46
-1

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 :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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