wordpress custom fields css/javascript for pages


/ Published in: PHP
Save to your folder(s)

create two custom fields: one called custom_css and one called custom_js.


Copy this code and paste it in your HTML
  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. ?>

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.