• I would like to have full width images on my site, but I would like the text content to NOT be full width since it’s hard to read.

    How can I change either the text content width OR the image width?

    These are my options now:
    – When I set the default layout to be centered the text is a good with but the images are then too small.

    – When I set the default layout to fullwidth both text and images are fullwidth, then I would like to set the text width to smaller.

    Can you please help me?

Viewing 15 replies - 1 through 15 (of 27 total)
  • Hey there karinlin,

    How are you doing today?

    Would you mind posting link to your site where I can see this with the first option set up for example and we can try to increase image size with some CSS.

    Best regards,
    Bojan

    Thread Starter karinlin

    (@karinlin)

    Hi Bojan, thanks for your quick reply. Here is my webpage: https://karintri.com/

    I have now set it the default layout to centered.
    The site layout is set to “Boxed layout with content width of 1218px”

    Please let me now how to change the css.

    Hey again karinlin,

    Thanks for the link, I’ve checked your site and you should be able to achieve that by adding the following CSS code to Appearance -> Theme Options -> Design -> Custom CSS:

    div#primary {
        width: 100%;
    }
    
    div#primary .entry-content p span {
        display: block;
        width: 61.5763547%;
        margin-left: auto;
        margin-right: auto;
    }

    This should be the result https://screencast.com/t/ANo5GBlvF.

    Hope this helps ??

    Cheers,
    Bojan

    Thread Starter karinlin

    (@karinlin)

    Hi Bojan,
    Thanks for your help. I tried to enter that code snippet into the Custom CSS, and it looks good on the first post. However, the following posts (after the full width picture) now have the text full width again? Same when you click into the post-pages, only the first one have the text centered.

    Do you know how I could fix this? Thank you!

    Hey again karinlin,

    Sorry about that, that was completely my bad. When I checked that page the first time I saw that text inside p element is placed in span so I just assumed they all are and never actually scrolled down to check the rest.

    After checking again there is no way we can target p elements that has only text and no image with just CSS since images are also placed in p elements so we’ll have to use some jQuery for this. Please try placing this at the end of your theme functions.php (Ideally you’d want to use child theme so you don’t lose changes when you update the theme):

    <?php
    add_action('wp_footer','my1_javascript_function');
    function my1_javascript_function(){
    ?>
    <script>
    jQuery(function(){
    ;(function ($) {$(function () {$(".entry-content p").each(function() {var $me = $(this); if ($me.find("a img").length) return true; $me.closest("p").addClass("reducewidth"); } ); }); })(jQuery);
    })
    </script>
    <?php
    }
    ?>

    This script will search for p elements that are not having img inside them and add class to those p elements which we can later use to reduce the width with CSS.

    When done with that replace the CSS code I provided above with this one:

    div#primary {
        width: 100%;
    }
    
    .reducewidth {
    width: 61.5763547%;
    margin-left: auto;
    margin-right: auto;
    }

    This should fix it on both blog and single post pages.

    Hope this helps ??

    Cheers,
    Bojan

    Thread Starter karinlin

    (@karinlin)

    Perfect, thank you so much!

    Glad I could help ??

    Have a nice day!

    Cheers,
    Bojan

    Thread Starter karinlin

    (@karinlin)

    Hi again,
    Could you please help me with a little detail about the pictures? How do I set all the pictures to be centered, say in old posts where the width isn’t wide enough, I would like them centered. Now they are to the left.

    Hey again,

    Sure thing ??

    Can you just give me few examples (links) where this happens so I don’t have to search for it on your site? I tried looking but couldn’t find those images.

    Best regards,
    Bojan

    Thread Starter karinlin

    (@karinlin)

    Hey again,

    Please try adding the following:

    .single .entry-content p a img {
        margin-left: auto;
        margin-right: auto;
        display: block;
    }

    This should center content images on your single post pages.

    Best regards,
    Bojan

    Thread Starter karinlin

    (@karinlin)

    Great, thanks for your help!

    when ever internet speed is slow my template and theme cant uploaded clearly.its all interface get distracted [Non-WordPress website redacted]

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Glad I could help ??

    Cheers,
    Bojan

Viewing 15 replies - 1 through 15 (of 27 total)
  • The topic ‘Full width image when centered content’ is closed to new replies.