Tagged: Lightbox, prettyphoto
-
AuthorPosts
-
November 15, 2013 at 11:12 am #189135
Hey guys
I wanted to add a download link to the lightbox and I found this
https://kriesi.at/support/topic/download-links-inside-the-lightbox/#post-24422
I was able to follow along and get this working on my site. But I can’t get it to work in my child theme. As of now I changed the parent jquery.prettyPhoto.js file and everything is working.Forgive me as I don’t know the proper names for what I want to do. But I know i need to add something to the child functions.php file to reference where I want the new prettyphoto js file to live and then place it in my child directory. But I can’t get this right. I tried doing…
add_filter('avia_load_prettyphoto', 'avia_include_prettyphoto_template', 15, 1); function avia_include_prettyphoto_template($paths) { $template_url = get_stylesheet_directory(); array_unshift($paths, $template_url.'/prettyphoto/'); return $paths; }
But I made this up, just modifying a previous filter you gave me to change some shortcode files. Can you please give me the code for the child functions file and then instructions on were to place my modified prettyphoto js file.
thanks
November 16, 2013 at 9:17 am #189554Hi allegrabillings!
Use following code to replace the prettyphoto js url
if(!is_admin()) { add_action('wp_enqueue_scripts', 'avia_register_child_frontend_scripts', 100); } function avia_register_child_frontend_scripts() { $child_theme_url = get_stylesheet_directory_uri(); wp_dequeue_script('avia-prettyPhoto'); //register js wp_register_script( 'avia-prettyPhoto', $child_theme_url.'/js/jquery.prettyPhoto.js', array('jquery'), "2.0", false ); wp_enqueue_script( 'avia-prettyPhoto' ); }
and place the modified jquery.prettyPhoto.js file into the “js” folder inside your child theme folder.
Regards,
PeterNovember 16, 2013 at 5:53 pm #189622Thanks Peter,
That leads me to one potential conflict, but I don’t know for sure so I will post it and let you tell me if there will be one or not. I just can’t yet wrap my head around php code.previously I wanted to add a js file for google link tracking. you gave me almost the same code to add a js folder in my child theme and then place the google file in that child js folder. It looks like this…
if(!is_admin()) add_action('wp_enqueue_scripts', 'avia_register_child_frontend_scripts', 100, 1); function avia_register_child_frontend_scripts() { $child_theme_url = get_stylesheet_directory_uri(); //register js wp_register_script( 'avia-js-child-theme', $child_theme_url.'/js/googlelink.js', array('jquery'), 1, false ); wp_enqueue_script( 'avia-js-child-theme' ); }
your new code in the above post for prettyPhoto is very much the same. So if I paste your new code after this code in my functions file, i dont know if that will make a potential conflict some how. can I use both as is, or do I need to combine them some how?
November 17, 2013 at 3:33 pm #189806Hey!
Use following code to combine both mods
if(!is_admin()) add_action('wp_enqueue_scripts', 'avia_register_child_frontend_scripts', 100); function avia_register_child_frontend_scripts() { $child_theme_url = get_stylesheet_directory_uri(); wp_register_script( 'avia-js-child-theme', $child_theme_url.'/js/googlelink.js', array('jquery'), 1, false ); wp_enqueue_script( 'avia-js-child-theme' ); wp_dequeue_script('avia-prettyPhoto'); wp_register_script( 'avia-prettyPhoto', $child_theme_url.'/js/jquery.prettyPhoto.js', array('jquery'), "2.0", false ); wp_enqueue_script( 'avia-prettyPhoto' ); }
Regards,
PeterNovember 19, 2013 at 12:31 am #190366Hey Peter,
thanks for combining these for me. Will you please look it over and make sure there isn’t a slight error somewhere. I went ahead and replaced the default prettyphoto js file back into the parent theme, and then placed the modified prettyPhoto file in the existing js folder in my child theme and then placed the new modified code in my child functions file. And now the effect I was previously getting is gone. So it is still reading the parent prettyphoto code.thanks for looking into this further.
November 19, 2013 at 10:44 am #190504Hey!
I changed the code of the first line a bit (#189806) – please try it again
Regards,
PeterNovember 20, 2013 at 7:17 am #190843Okay Peter,
I tried that without the 1 and it still didn’t work. Forgive what I am about to say as I know for a fact I am talking out of my shorts, as I don’t really understand php code at all. But figured you are obviously on the right track and tweaking stuff to get it to work. So I looked on the WP codex at the register_scripts, enqueue, dequeue etc to try and learn more about them for my own sake, definitely still way over my head, but on the dequeue script documentation it was talking about adding deregister along with dequeue, but I don’t know in what context as I didn’t understand it. So thought maybe that is the trouble, but what I gathered was the dequeue was turning off the script I think and then the following register and enqueue scripts are turning it back on but in the child theme location. I was just trying to figure out what the lines of code actually do.Again without knowing anything I thought it was interesting that the dequeue, register and enqueue scripts all had the same name ‘avia-prettyPhoto’ I thought maybe the new child location script name should be different. This is based off the fact that most of the mod functions and filters you and devin have given me in the past seam to have arbitrarily made up names when including them into the child theme. So I simply changed the wp_register_script and enqueue_script name to ‘prettyPhoto’ instead of the ‘avia-prettyPhoto’ that we used in the dequeue-script before it in your code. And it then worked so then I used avia-Photo and it still worked.
So knowing that, will you look at it again and see if I can infact just use some made up new name for those two lines and call it good or is it more sophisticated than that, and that may give you a lightbulb moment to improve the code. Thanks Please advise.
November 20, 2013 at 8:39 am #190850Hi!
The enqueue/dequeue name shouldn’t be a problem – however if you think it causes the issue try following code instead
add_action('wp_enqueue_scripts', 'avia_register_child_frontend_scripts', 10); function avia_register_child_frontend_scripts() { $child_theme_url = get_stylesheet_directory_uri(); wp_register_script( 'avia-js-child-theme', $child_theme_url.'/js/googlelink.js', array('jquery'), 1, false ); wp_enqueue_script( 'avia-js-child-theme' ); wp_dequeue_script('avia-prettyPhoto'); wp_register_script( 'avia-newlightbox', $child_theme_url.'/js/jquery.prettyPhoto.js', array('jquery'), "2.0", true); wp_enqueue_script( 'avia-newlightbox' ); }
I also changed the priority from 100 to 10 – maybe 100 is too late for the lightbox script…
Regards,
PeterNovember 20, 2013 at 6:40 pm #191069Hey Peter thanks for looking again,
As I mentioned I don’t have any bases to think anything specific, I was just blindly trying things. The previous code with priority 100 and “2.0”, false); worked as long as the register and enqueue name as different than the dequeue.That being said I have no doubt that the new code will work. but before I implement it, what is more ideal from your end as you know what the script is doing? to have 100 or 10 for the priority and to have false or true after the “2.0”? I saw you changed the latter also.
add_action('wp_enqueue_scripts', 'avia_register_child_frontend_scripts', 100); function avia_register_child_frontend_scripts() { $child_theme_url = get_stylesheet_directory_uri(); wp_register_script( 'avia-js-child-theme', $child_theme_url.'/js/googlelink.js', array('jquery'), 1, false ); wp_enqueue_script( 'avia-js-child-theme' ); wp_dequeue_script('avia-prettyPhoto'); wp_register_script( 'avia-newlightbox', $child_theme_url.'/js/jquery.prettyPhoto.js', array('jquery'), "2.0", false); wp_enqueue_script( 'avia-newlightbox' ); }
or
add_action('wp_enqueue_scripts', 'avia_register_child_frontend_scripts', 10); function avia_register_child_frontend_scripts() { $child_theme_url = get_stylesheet_directory_uri(); wp_register_script( 'avia-js-child-theme', $child_theme_url.'/js/googlelink.js', array('jquery'), 1, false ); wp_enqueue_script( 'avia-js-child-theme' ); wp_dequeue_script('avia-prettyPhoto'); wp_register_script( 'avia-newlightbox', $child_theme_url.'/js/jquery.prettyPhoto.js', array('jquery'), "2.0", true); wp_enqueue_script( 'avia-newlightbox' ); }
November 21, 2013 at 8:51 am #191358Hey!
Yes, true will make sure that the prettyphoto script loads at the bottom of the page (footer section). I’m not sure why the code doesn’t work for you that’s why I tried to change different things to get it working. You can also set it back to false if “true” doesn’t work. As mentioned in my last post I changed the priority from 100 to 10 because the low priority of 100 may breaks the lightbox script. By default a priority of 10 is used for actions.
Cheers!
PeterNovember 22, 2013 at 6:39 pm #191970Thanks for the info Peter.
To wrap this up, after more testing if I use the priority of 10 and true to load at the bottom of the page and the names of the different scripts are identical it does in fact load. With the names the same and the values of 100 and false it doesn’t not load. But with the 100 and false and if I change the name of the new child scripts it will once again load.So In conclusion I reverted the names to the same (like you started) and used you 10 and true values as my choice to the variables.
Thanks for staying with this to get more clarity.
-
AuthorPosts
- The topic ‘updating prettyPhoto in child theme’ is closed to new replies.