-
AuthorPosts
-
February 19, 2021 at 7:46 pm #1282314
Hello,
I use the extension WP Image Zoom and I need to put the class “zoooom” on all images.
Do you know how to do it just one time for every images ?Thanks and best regards.
February 20, 2021 at 12:52 am #1282347Not all Images are inserted in Enfold as
<img src=" …
a lot of them are only background-images f.e.: https://kriesi.at/themes/enfold-2017/elements/masonry/you can try this in child-theme functions.php if you need that class directly on the img tag itself
if you need it on the parent element tell me – then we can find that parent by another selector.
( i think even an each function is not neccessary)function add_class_to_images(){ ?> <script> (function($) { $('img').addClass('zoooom'); })(jQuery); </script> <?php } add_action('wp_footer', 'add_class_to_images');
February 21, 2021 at 5:45 am #1282588February 21, 2021 at 6:05 pm #1282618Thank you very much Guenni,
I tried it and it’s very powerfull.
However, I just realised that I only wan’t the class images in articles and pages.
I guess your script would would work with “if” ” and “then” condition however my PHP is quite poor.
If you have time please help me other wise don’t worry. I will add the class manually in every images appearing in article or pages.Best regards and once again thank you.
Muriel.
February 21, 2021 at 6:05 pm #1282619This reply has been marked as private.February 22, 2021 at 12:20 pm #1282767Well you can use every conditional tag wordpress offers: https://codex.wordpress.org/Conditional_Tags
a douple pipe is a logic or and a double && is a logic and
so you can start with – the if clause wraps the script that should be used.
e.g.:function add_class_to_images(){ if(is_page() || is_singular('post') || is_singular('portfolio')){ ?> <script> (function($) { $('img').addClass('zoooom'); })(jQuery); </script> <?php } // this closes the if statement } // this closes the function itself add_action('wp_footer', 'add_class_to_images');
//more specific selections can be made within the brackets. (e.g. - which pages should be affected via an array). // IDs without quotes and page names like privacy , portfolio etc. with quotes if(is_page(array( 1396, 1617, 'privacy'))){ …
it might be better to see your pages it concerns to give exact help on that.
February 22, 2021 at 1:57 pm #1282797Thank you very much Guenni. Your help is awesome.
I wan’t this class to be on all pages but not the homepage.
My website address is down below.
Best regards.
Muriel.
February 22, 2021 at 3:30 pm #1282826sorry no private content for me – i’m participant as you!
but all pages except the front page :
function add_class_to_images(){ if(is_page() && !is_front_page()){ ?> <script> (function($) { $('img').addClass('zoooom'); })(jQuery); </script> <?php } } add_action('wp_footer', 'add_class_to_images');
the Exclamation mark indicates a not logic so it is all pages but not front page
PS: is_home() might work here too – but there is a little difference inbetween is_front_page() and is_home()February 23, 2021 at 11:19 am #1283024Hi,
Thanks again for helping out @guenni007, it’s much appreciated as always :-)
Best regards,
Rikard -
AuthorPosts
- You must be logged in to reply to this topic.