Add a new 'theme' to SyntaxHighlighter Evolved
To publish code on my site I use the WordPress plugin SyntaxHighlighter Evolved. On the website of the author is described how to add a new theme to the plugin. If you follow the instructions it will work out fine. Only one small detail, wordpress will generate an error notice. If you have wp-debug on this will be visible: Notice: wp_enqueue_style was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or init hooks.
Simply put this is caused because the codes starts to early. By wrapping it in a function this is solved:
1 2 3 4 56 7 8 9
function yoursyntheme_enqueue_styles() { // Prevent: Notice: wp_enqueue_style was called incorrectly. wp_register_style( 'syntaxhighlighter-theme-yoursyntheme', content_url( 'path/to/your/theme.css' ), array( 'syntaxhighlighter-core' ), '1.2.3' // A version number. It doesn’t matter what you set it to, it’s for browser cache busting ); }
Now that the stylesheet has been registered we need to inform the SyntaxHighlighter plugin about it:
10 11 12 13 1415 16
add_filter( 'syntaxhighlighter_themes', 'your_function_name_here' ); function your_function_name_here( $themes ) { $themes['yoursyntheme'] = 'The Name Of Your Theme'; return $themes; }
And likes this everything works without any error, just like we wanted. The theme that I created myself for this site is available for download. You could use this as is, or as a starting point for your own theme. Have fun!