• Your plugin is a great solution for showing different widget blocks on different category pages.

    However, I noticed that hidden blocks keep their margin and padding, so that even when a block is hidden, there is a bit of white space representing its margin and padding. I have solved it temporarily by custom css but it’s a bit tricky since I of course do want margins and padding on the visible blocks, so I need to customise the css for each block.

    Do you know what I mean and is this something that could be fixed?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter Karl Andersson

    (@swekarl)

    Adding a simple float: left to the .widget class solved it (margin collapse).

    Plugin Author landwire

    (@landwire)

    Hi Karl,
    It would help me if you could post a URL to a demo page where you have that problem. The plugin checks server side if the “block logic” has to be applied and then does or does not render the block.

    It uses the PHP render_block filter: https://developer.www.ads-software.com/reference/hooks/render_block/

    And just returns nothing if the block should be hidden.

    if ($show_block) {
    		return $block_content;
    	} else {
    		return '';
    	}

    `

    Maybe the theme or any other plugin you use add any additional wrapper with the same filter out of my control?

    But thanks for that info. I quite likely should increase the priority of the render_block filter, so it hopefully does run later than any other calls to that filter. Will do that with the next update, likely for the release of 5.8.

    Plugin Author landwire

    (@landwire)

    And sorry for the late reply, I was on holiday the past week and only saw this today.

    Thread Starter Karl Andersson

    (@swekarl)

    Thanks for the reply and explanation. So maybe it’s another wrapper then, I’m using Genesis from Studiopress.

    The hidden block shows up in the HTML code like this:

    <section id="block-9" class="widget widget_block"><div class="widget-wrap"></div></section>

    I’ll see if I can provide a live example, the current dev site is too messy to share here, especially since we can’t edit posts. But problem solved for now. I appreciate your willingness to help!

    Plugin Author landwire

    (@landwire)

    Hmm, I just tested it on simple core paragraph block in a widget area on a simple theme. There is none of that markup above, but just straight forward block markup from WordPress.

    Ok, I downloaded Genesis and it does add some markup to widgets.
    See:

    function genesis_register_widget_area( $args ) {
    
    	$defaults = [
    		'before_widget' => genesis_markup(
    			[
    				'open'    => '<section id="%%1$s" class="widget %%2$s"><div class="widget-wrap">',
    				'context' => 'widget-wrap',
    				'echo'    => false,
    			]
    		),
    		'after_widget'  => genesis_markup(
    			[
    				'close'   => '</div></section>' . "\n",
    				'context' => 'widget-wrap',
    				'echo'    => false,
    			]
    		),
    		'before_title'  => '<h4 class="widget-title widgettitle">',
    		'after_title'   => "</h4>\n",
    	];
    
    	/**
    	 * A filter on the default parameters used by <code>genesis_register_widget_area()</code>. For backward compatibility.
    	 *
    	 * @since 1.0.1
    	 */
    	$defaults = apply_filters( 'genesis_register_sidebar_defaults', $defaults, $args );
    
    	/**
    	 * A filter on the default parameters used by <code>genesis_register_widget_area()</code>.
    	 *
    	 * @since 2.1.0
    	 */
    	$defaults = apply_filters( 'genesis_register_widget_area_defaults', $defaults, $args );
    
    	$args = wp_parse_args( $args, $defaults );
    
    	return register_sidebar( $args );
    
    }

    So unfortunately this is really out of my control.

    Can I close this as resolved?

    Plugin Author landwire

    (@landwire)

    Obviously you can use their filters to change that markup, but that might break other things/styling.

    Thread Starter Karl Andersson

    (@swekarl)

    Aha, interesting that Genesis adds that. Yes, mark as resolved. Thanks for looking into it!

    Plugin Author landwire

    (@landwire)

    Ok, will do.
    Leave a plugin review if you like!

    Thread Starter Karl Andersson

    (@swekarl)

    I was already writing it. ??

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Margin and padding show up for hidden blocks’ is closed to new replies.