Posted By

scitrenbaumgmailcom on 01/11/10


Tagged

css wordpress fields custom


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

scitrenbaumgmailcom


wordpress custom fields css/javascript for pages


 / Published in: PHP
 

URL: http://www.designlessbetter.com/blogless/posts/page-specific-css-and-javascript-using-wordpress-custom-fields

create two custom fields: one called customcss and one called customjs.

  1. <?php
  2. $id = $wp_query->post->ID;
  3. $css_docs = get_post_meta($id, 'custom_css', false);
  4. $js_docs = get_post_meta($id, 'custom_javascript', false);
  5. if (!empty($css_docs))
  6. {
  7. echo '<!--Custom css for '.get_the_title().'.-->'."\n";
  8. foreach ($css_docs as $css)
  9. {
  10. echo '<link rel="stylesheet" href="'.$css.'" type="text/css" media="screen" />'."\n";
  11. }
  12. }
  13. if (!empty($js_docs))
  14. {
  15. echo '<!--Custom javascript for '.get_the_title().'.-->'."\n";
  16. foreach ($js_docs as $js)
  17. {
  18. echo '<script src="'.$js.'" type="text/javascript"></script>'."\n";
  19. }
  20. }
  21. ?>

Report this snippet  

You need to login to post a comment.