lundi 5 octobre 2015

How to use jQuery to load different images on specific pages in Wordpress

I'm newish to jQuery and hoping to use it primarily when working on Wordpress websites like this instance.

I am trying to load a unique logo on three specific portfolio pages. My aim is to use a unique class from each page and then add the image before a button with an ID of #scroll-down. Oddly, only the GPD_Logo_Colour1.gif shows up on all the pages. When I view the source code for the HTML markup I can see that jQuery loaded 2 of the three image with the GPD_Logo_Colour1.gif first, even though it is second in the jQuery code.

Do I have some incorrect syntax? or is the GPD_Logo_Colour1.gif cached? I'm really not sure where to look next for an answer. Thanks!

This is the code I've used in my functions.php file, in my child theme, to get the my.js file to be enqueued / load.

function evoc_child_script() {
wp_enqueue_script ('jquery');
wp_enqueue_script('jeremys javascript', 
get_stylesheet_directory_uri() . '/js/my.js', 
true);
}

add_action( 'wp_enqueue_scripts', 'evoc_child_script');

This the code in my my.js file

jQuery(document).ready(function(){

$('body.postid-239 #scroll-down' ).before('<img      src="http://ift.tt/1LtH3jQ"      />');

$('body.postid-192 #scroll-down' ).before('<img    src="http://ift.tt/1hm4e1o  content/uploads/2015/09/GPD_Logo_Colour1.gif" />');

$('body.postid-284 #scroll-down' ).before('<img src="http://ift.tt/1LtH3jR" />');

}); 



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire