Support

Account

Home Forums ACF PRO Flexible Content, Help Creating Dynamic Script to Detect Adjacent Flex Content Reply To: Flexible Content, Help Creating Dynamic Script to Detect Adjacent Flex Content

  • I think that your question “Why not just decrease the margin using CSS?… is a valid one.

    If these text blocks are stacked on top of each other this can easily be solved using CSS, although it may require adjustments to other CSS. In this case I would use a top margin instead of a bottom margin and then.

    
    /* assuming your container has a class of "text_block" */
    .text_block+.text_block {
      margin-top: 0;
    }
    

    To do it the way you’re doing it, before applying the margin bottom of 0 you also need to look at the next element of your array. If it is not a text-block as well then do not apply the margin bottom of 0. I don’t know much about array_search, but you would check here I think.

    
    
        if($after == 'text_block') {
            // check to see if the next block is a text block
            // if it is then do not apply these classes
            echo '<div id="text-block" class="text-center mt-5 mb-0 text-after">';
        } else {
            echo '<div id="text-block" class="text-center my-5">';
        }