Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #189135

    Hey guys
    I wanted to add a download link to the lightbox and I found this

    http://www.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

    #189554

    Hi 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,
    Peter

    #189622

    Thanks 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?

    #189806

    Hey!

    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,
    Peter

    #190366

    Hey 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.

    #190504

    Hey!

    I changed the code of the first line a bit (#189806) – please try it again

    Regards,
    Peter

    #190843

    Okay 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.

    #190850

    Hi!

    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,
    Peter

    #191069

    Hey 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' );
    }
    #191358

    Hey!

    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!
    Peter

    #191970

    Thanks 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.

Viewing 11 posts - 1 through 11 (of 11 total)

The topic ‘updating prettyPhoto in child theme’ is closed to new replies.