• Resolved Anonymous User 14978628

    (@anonymized-14978628)


    Hi Stefan,

    I am having trouble making custom media queries work with some of my images.

    In RWP settings, i have tried using the option “use when>image>class/size>is equal to” to attach a media query to an image class, but i can’t seem to get it working no matter what i do.

    I’m guessing perhaps i have the wrong class selected, as i can make my media query work when i make the rule “not equal to” which then targets everything on the page.

    Could you tell me how i can create correct rules for the following 2 image types on my page as shown on this test page?

    https://www.celebrityhealthcritic.com/testresponsifywp/

    I have tried many classes which didn’t work including

    fullwidth_image
    et_pb_fullwidth_image

    Thanks!

Viewing 15 replies - 1 through 15 (of 16 total)
  • Plugin Author stefanledin

    (@stefanledin)

    Hi Marty!
    Can you turn on the debug mode so we can see what RWP does? 🙂

    Thread Starter Anonymous User 14978628

    (@anonymized-14978628)

    Hey Stefan, sorry about that. Debug was on but Autoptimize was removing comments from html. Have fixed this now! 😉

    Plugin Author stefanledin

    (@stefanledin)

    Great!
    Could you send me a screenshot of your MQ-settings?

    Thread Starter Anonymous User 14978628

    (@anonymized-14978628)

    sure,
    RWP-MQ

    I have tried changing size is/class option with no effect. Just for testing i selected a very small image to show for tablet only so it the change would be obvious, but can’t seem to target the image class/size.

    I have been able to target it indirectly but setting a rule to apply to anything that isn’t “sidebar” which is an image size i have been able to create a rule for.

    https://onedrive.live.com/?cid=F006A25245D104BB&id=F006A25245D104BB%21107585&parId=F006A25245D104BB%21105&o=OneUp

    Thread Starter Anonymous User 14978628

    (@anonymized-14978628)

    Hey Stefan, just had an idea which may make this easier to resolve.

    Do you have a local test site? I was wondering whether i could give you a link to download my theme with a page template that has some images on it, and perhaps you could see if you could get some media queries working with those images and RWP?

    Have literally been struggling with this the past few days and just can’t get it to work!

    Plugin Author stefanledin

    (@stefanledin)

    Oh that would be great! It’s always much easier to debug when you have something “real” to see and touch 😉

    Thread Starter Anonymous User 14978628

    (@anonymized-14978628)

    Great! You can find the theme linked below. I’ve also included some install instructions.
    I zipped the theme manually so if you have trouble installing that i’ve also included an unzipped version that can be copied directly to your theme folder. The other file is the a template that contains several placeholder images.

    Thanks!

    https://onedrive.live.com/?id=F006A25245D104BB%21107587&cid=F006A25245D104BB

    Thread Starter Anonymous User 14978628

    (@anonymized-14978628)

    Hey Stefan,

    I’ve just noticed using the custom code in my theme that the “alt” tag is missing for my featured image. Is there a way to get the alt tag displayed again? The code i’ve manually inserted in my theme is:

    <?php
    $thumbnail_id = get_post_thumbnail_id( $post->ID );
    echo rwp_img( $thumbnail_id, array(
    ‘sizes’ => array(‘extra-image-single-post’, ‘featured-tablet-p’, ‘featured-phone-l’, ‘featured-phone-p’ ),
    ‘attributes’ => array(
    ‘sizes’ => ‘(min-width: 1024px) 1280px, (min-width: 768px) 1036px, (min-width: 568px) 900px, 507px’
    )
    ));
    ?>

    Thanks

    Plugin Author stefanledin

    (@stefanledin)

    I can’t open the ZIP file I’m afraid :/ I guess it’s a PC/Mac issue, if that thing’s still around 😉

    Regarding the alt attribute: you can add another key/value pair to the attributes array. Like this:

    
    <?php
    $thumbnail_id = get_post_thumbnail_id( $post->ID );
    echo rwp_img( $thumbnail_id, array(
        ‘sizes’ => array(‘extra-image-single-post’, ‘featured-tablet-p’, ‘featured-phone-l’, ‘featured-phone-p’ ),
        ‘attributes’ => array(
            ‘sizes’ => ‘(min-width: 1024px) 1280px, (min-width: 768px) 1036px, (min-width: 568px) 900px, 507px’,
            'alt' => 'Alt text goes here'
        )
    ));
    ?>
    
    Plugin Author stefanledin

    (@stefanledin)

    Okey, I’ve got things up and running now. (Thanks to online zip-openers)
    The problem seems to be that custom css classes is added to the wrapping <div>, not the <img> itself. RWP doesn’t “see” anything else but the <img> elements, so that’s why it takes effect when you select the “not equal to” option.

    Thread Starter Anonymous User 14978628

    (@anonymized-14978628)

    ok, well thanks for investigating the issue. I actually have it working quite nicely with the “not equal to” option, so not a big issue.

    I tried adding the alt code you posted but it gives me the following error

    ” Parse error: syntax error, unexpected ‘:’, expecting ‘,’ or ‘)’ in”

    Also, will that alt code automatically insert the alt text that exists for a particular image, as what you put above looks like i would have to manually enter the alt text? The code i posted above is put in my single.php template so it displays different featured images for different posts.

    Plugin Author stefanledin

    (@stefanledin)

    If you just copy/pasted my code, you should replace my ‘ with ‘

    It wont add the alt text, it’s hard coded in my example. You’ll get it like this:
    $alt = get_post_meta( $thumbnail_id, '_wp_attachment_image_alt', true);

    Thread Starter Anonymous User 14978628

    (@anonymized-14978628)

    I’ve tried adding the new code as follows but it doesn’t produce any alt text for the image:

    <?php
    
    $thumbnail_id = get_post_thumbnail_id( $post->ID );
    $alt = get_post_meta( $thumbnail_id, '_wp_attachment_image_alt', true);
    echo rwp_img( $thumbnail_id, array(
        'sizes' => array('extra-image-single-post', 'featured-tablet-p', 'featured-phone-l', 'featured-phone-p' ),
        'attributes' => array(
            'sizes' => '(min-width: 1024px) 1280px, (min-width: 768px) 1036px, (min-width: 568px) 900px, 507px'
    )
    ));
    ?>
    Plugin Author stefanledin

    (@stefanledin)

    No, you’re only saving the alt text to a variable that you doesn’t do anything with. It should be the value to the alt key in the attributes array.

    
    <?php
    $thumbnail_id = get_post_thumbnail_id( $post->ID );
    echo rwp_img( $thumbnail_id, array(
        'sizes' => array('extra-image-single-post', 'featured-tablet-p', 'featured-phone-l', 'featured-phone-p' ),
        'attributes' => array(
            'sizes' => '(min-width: 1024px) 1280px, (min-width: 768px) 1036px, (min-width: 568px) 900px, 507px',
            'alt' => get_post_meta( $thumbnail_id, '_wp_attachment_image_alt', true)
    )
    ));
    ?>
    
    Thread Starter Anonymous User 14978628

    (@anonymized-14978628)

    facepalm, added it as you said and it’s working perfect now. Thanks Stefan!

Viewing 15 replies - 1 through 15 (of 16 total)

The topic ‘Custom Media Query Selector’ is closed to new replies.