/ Published in: PHP
Example of loading thickbox and syntaxhighlighter conditionally from the functions.php of a wordpress theme.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
add_action('wp_print_styles','my_conditional_script'); function my_conditional_script() { global $post; wp_enqueue_script('thickbox'); wp_enqueue_style('thickbox'); } if (is_single() && strpost($post->post_content, '<pre') !== false) { $style = get_stylesheet_directory_uri() . '/syntaxhighlighter/style.css'; wp_register_style('sh-style', $style); wp_enqueue_style('sh-style'); $script = get_stylesheet_directory_uri() . '/syntaxhighlighter/script.js'; wp_register_style('sh-script', $script); wp_enqueue_style('sh-script'); } }