Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other How to install highlight.js on wordpress site? Reply To: How to install highlight.js on wordpress site?

#167621
MrEidsen
Participant

It is still not working… hmm… And no you didn’t confuse me too much. I have been learning a bit of php and have a basic understanding of computer programming (with python… so I don’t know so much about server programming yet), however, I don’t know enough php to understand the code beyond your explanation.

I went into the functions.php file under my themes folder, and I wanted to ask, is it supposed to have only one line of code in it? As I opened it for the first time, it contains only the this line of code: require_once(TEMPLATEPATH . ‘/thesis.php’);

I don’t even know if I am even in the correct directory, but I am not completely computer illiterate so I imagine that isn’t the problem (hopefully). Hmm but I noticed under the folder “wp_includes” there is also a functions.php as well as “js” and “css” folders… Could it possibly be that I should write the code to this functions.php and put the js file and css file into these respective folders?

Anyway I copied and pasted your code into the functions.php file under the thesis theme file and changed the file names to link to the proper directory in relevance to the functions.php folder, and my code is exactly as this:
function my_cool_scripts_and_styles()
{
/**
* OUTPUTS JAVASCRIPT: highlightjs
* wp_enqueue_script( $handle, $src, $dependency, $version, $in_footer );
*
* If you only need this to show up on certain pages wrap it in a wordpress conditional tag
* so for example:
* if ( is_page(‘some-page’) ) { wp_enqueue_script… } <– ended for brevity
*/
wp_enqueue_script(‘highlightjs’, get_template_directory_uri() . ‘/lib/js/highlight.pack.js’, array(), ‘8.0’, true);

/**
 *      OUTPUTS CSS
 *      wp_enqueue_style( $handle, $src, $dependency, $version, $media );
 */
 wp_enqueue_style( 'syntax-highlight-style', get_template_directory_uri() . '/lib/css/railscasts.css', array(), '1.0', 'all' );

} add_action( ‘wp_enqueue_scripts’, ‘my_cool_scripts_and_styles’ );

If there is something wrong with the changes I made or if I missed a change, it would be very kind of you to point it out to me.

I also had a couple questions about the code here, did I need to fill out get_template_directory_uri() and put the file directory directly into the parentheses? Or is it concatenated with the . and plugged in that way? This is what I assume, I am trying to understand how this function works.

Also, how can I know if this uses jquery or not? I tried it with both settings, and it didn’t make any difference.

I apologize for the many questions in a single post… But I assume there is a rather large time difference between us, so I want to get as many questions and info as I can so this can be fixed faster… Thank you so much for your patience and help. I really appreciate it.

By the way, here is a link to a page that I have formatted the way which should use this syntax highlighter. Maybe it would help you to have a look at the code here?
http://webdev101.net/2014/how-to-code-simple-horizontal-navigation-bars/