Con jQuery possiamo evidenziare un commento di WordPress linkato tramite un hash (come ad esempio in sito.com/categoria/post/#comment-12
) con relativa semplicità. Vediamo come fare.
Aggiungete il seguente codice al file functions.php
:
add_action( 'wp_head', 'jquery_register' );
function jquery_register() {
if ( !is_admin() ) {
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', ( 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js' ), false, null, true );
wp_enqueue_script( 'jquery' );
}
}
add_action('wp_head','highlight_hash');
function highlight_hash(){
echo '<script type="text/javascript">
$(document).ready(function() {
if(window.location.hash) {
$(window.location.hash).addClass('highlight');
}
});
</script>';
}
Ovviamente dovete definire la classe CSS corrispondente nel vostro file CSS principale:
.highlight {
background: #f5eac6;
}