Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #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.

    #1282347

    Not 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');
    #1282588

    Hi,

    Thanks for helping out @guenni007 :-)

    Best regards,
    Rikard

    #1282618

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

    #1282619
    This reply has been marked as private.
    #1282767

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

    #1282797

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

    #1282826

    sorry 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()

    #1283024

    Hi,

    Thanks again for helping out @guenni007, it’s much appreciated as always :-)

    Best regards,
    Rikard

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