I am trying to dynamically add margin-bottom property to my widget. For example, I am inputting the value "50px" from my widget and want to use this value to adjust margin-bottom property for the widget. The main purpose is to dynamically add space between my widgets.

This is what I have done so far. Its getting me a white screen of death. I think the problem is at margin-bottom: $variable.

Is it allowed to add inline css in widget function? How do I get the $space valye in the div tag?

    function widget( $args, $instance ) {
        $space= "200px";
        echo "<html>";
        echo "<body>";
        echo "<div style=margin-bottom: <?echo $space; ?>>";
        if (!empty($photos)):
             //Loop through each attachment..

             foreach ($photos as $photo_id => $photo) : 

                 $url = wp_get_attachment_url($photo_id);
                 $position = strpos($content, $url);

                    echo wp_get_attachment_image($photo_id, 'thumbnail') ;
         echo "</div>";
         echo "</body>";
         echo "</html>";
  • If that causes white screen please always enable WP_DEBUG and include error messages verbatim into your question.
    – Rarst
    Commented Nov 22, 2015 at 12:36
  • You are missing a semi-colon after the third echo.
    – s_ha_dum
    Commented Nov 22, 2015 at 15:23
  • Thank you for pointing it out. I corrected the third echo statement. I also noticed that I was write div style tag with wrong syntax. I have corrected it. But its still not increasing space between my widgets. Am I writing the style correctly? is there another way to do this?
    – Beans
    Commented Nov 22, 2015 at 19:17

1 Answer 1


Googled some more and found out that closing php tags and writing html as it is a better practice as compared to writing html inside. Made the following changes to the code shared above:

      <div style="margin-bottom:<?php echo $space; ?>" >
      //rest of the code
      //rest of the code

Space between widgets added!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.