[Prism]3 steps to highlight your code in WordPress post without plugin
  1. Select your langurage and download the .css and .js files from http://prismjs.com/download.html **don’t forget choose the code theme”. At the end of the page, you can preview the theme you chosen.
  2.  Then, upload the .css and .js files to your theme file by FTP, such as, ‘your site/wp-content/themes/your theme/’.
  3. Add the following code in the your theme/function.php file
function add_prism() {
wp_register_style('prismCSS', get_stylesheet_directory_uri() . '/prism.css');
wp_register_script('prismJS', get_stylesheet_directory_uri() . '/prism.js');
global $post, $wp_query;
$post_contents = '';
if ( is_singular() ) {
$post_contents = $post->post_content;
} elseif ( is_archive() || (is_front_page() && is_home())) {
$post_ids = wp_list_pluck( $wp_query->posts, 'ID' );
foreach ( $post_ids as $post_id ) {
$post_contents .= get_post_field( 'post_content', $post_id );
if ( strpos( $post_contents, '

IMPORTANT i tried to create the child theme of the Editorial Mag theme, and put the .css and .js in the child theme. It doesn’t work. Solution: put them in the main theme file, just like i showed in the poster. Maybe you have some other solutions. Please leave a message. Thanks.

News Reporter
Dr. Lu

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Skip to toolbar