Support » Developing with WordPress » Using existing jQuery code of theme or creating new code

  • mhille31

    (@mhille31)


    Hello,
    I’m quite new to WordPress, Javascript, jQuery, PHP and I want to add a functionality to my website:
    I’ve installed a theme, what offers a hover effect to images in the gallery, what works fine. This hover effect on an image I want to have now in addition if the mouse is over a listing point of a text list beside which refers to the image with the hover effect. This should work with the other images and list points, too. This function is not part of the theme, I have to do it by my own, that´s why I post this here and not in the theme forum.
    My question is now, which way I should go:

    A) Using the existing jQuery-Code from the theme, what is a bit tricky for me, because I haven’t got so much experiences with jQuery and no idea where to change. Maybe there is a tutorial how I can separate my needed function, any hint?

    B) Writing own jQuery-Code to get the task solved. Probably it is not the best idea writing some existing code for the second time, producing redundant code. Otherwise in that case I would learn something more about jQuery…

    Or is there another way for me? What would you recommend me or how would you solve this task?

    Thanks in advance.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi, I would suggest using a child theme for this and use its own functions.php. That way whenever the Parent theme updates your code wouldn’t be lost.

    Also, use wp_enqueue_script() to add your own jQuery.

    Here’s how to use jQuery in WordPress link. It’s a very useful topic.

    Moderator bcworkz

    (@bcworkz)

    Try to determine what is changed to achieve the image hover effect. It could be as simple as adding a class attribute value to a particular element. You can then add your own script that does the same thing on the mouseover event of your listing points.

    Yes, it would be simpler to add listing point selectors to the existing code, but then you run into the issue of your changes being lost as Rey Den Nalasa points out. To avoid this, some redundancy is required. If I’m right about what’s needs to be changed, there’s not much code involved, so the redundancy wouldn’t amount to much.

    Thank you so much for the detailed answers.
    I’ll try it. 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.