0

At the VERY core, my question is - how to remove linebreaks on a single ACF field that is inserted with the ACF shortcode.

I have a lot of "shortcodes within shortcodes" here so I will walk this thing through.

First, I am using ACF to dictate the direction of the content. I have two ACF fields, one where I am inputting into the WordPress WYSIWYG, and the other that I am inputting into the first ACF field by means of the ACF Shortcode:

[acf field="home-icons"]

The contents of the home-icons field is this (using a custom shortcode and Boostrap 3 Shortcodes):

[row xclass="home-icons"]
[column sm="6"][flaticon class="hourglass"][/flaticon] Saves Time[/column]
[column sm="6"][flaticon class="graph-upward"][/flaticon] Benchmarking[/column]
[/row]
[row xclass="home-icons"]
[column sm="6"][flaticon class="24h"][/flaticon] Instant and secure access[/column]
[column sm="6"][flaticon class="site-settings"][/flaticon] Customization[/column]
[/row]

This is how I am building my shortcode, flaticon:

function flaticon( $atts, $content = null ) {
    $a = shortcode_atts( array(
        'class' => 'flaticon',
    ), $atts );

    return '<i class="btn-icon btn-footer flaticon-' . esc_attr($a['class']) . '"></i>' . $content . '';
}
add_shortcode( 'flaticon', 'flaticon' );

This is the intended output:

<div class="row home-icons">
<div class=" col-sm-6"><i class="btn-icon btn-footer flaticon-hourglass"></i> Saves Time</div>
<div class=" col-sm-6"><i class="btn-icon btn-footer flaticon-graph-upward"></i>&nbsp;Benchmarking</div>
</div>

This is the actual output:

<div class="row home-icons"><br>
<div class=" col-sm-6"><i class="btn-icon btn-footer flaticon-hourglass"></i> Saves Time</div><br>
<div class=" col-sm-6"><i class="btn-icon btn-footer flaticon-graph-upward"></i>&nbsp;Benchmarking</div><br>
</div>

It is adding unnecessary line breaks which shift the content so the icons don't line up. Now the issue is, ACF uses acf_the_content and I don't want to remove line breaks for everything, just that field (home-icons), but since it is a shortcode, I'm not sure how to target it directly.

Yes, I realize if I had everything on one line there is a chance it might be fine, but this is going to get handed over to a client and I'm not going to assume they would keep anything intact or remember to do so.

  • 2
    Why do you use the ACF shortcode at all? seems like you have the knowledge to replace that with one of your own in which you will be free to remove whatever you want. – Mark Kaplun Jan 7 '15 at 18:37
  • @MarkKaplun Bootstrap 3 Shortcodes can't be nested. – Aibrean Jan 7 '15 at 18:51
  • I have to double @MarkKaplun here: Why shortcodes inside shortcodes? And why can't "Bootstrap 3 Shortcodes" not be nested? Is this yet another plugin? If so: Even there is a function powering the shortcode (that you can use instead). – kaiser Jan 8 '15 at 0:36
  • The Bootstrap 3 Shortcodes provide the grid system (as well as a bunch of other utilities). Yes, I could in theory include DIVs in the text view, but that's not ideal. I could also make a different set for these off-chance scenarios. That specific shortcode creator is said to be working on a nested solution, but right now they don't nest within themselves. I can put mine in there though. At the VERY core, my question is - how to remove linebreaks on a single ACF field that is inserted with the ACF shortcode. – Aibrean Jan 8 '15 at 15:25
0

It was solved by a coworker.

    function removebreaks($content)
{
    $content = str_replace('<br>', '', $content);
    $content = str_replace('<br/>', '', $content);
    $content = str_replace('<br />', '', $content);
    $content = str_replace('<BR>', '', $content);
    $content = str_replace('<BR/>', '', $content);
    $content = str_replace('<BR />', '', $content);

    return $content;
}
add_filter('acf_the_content', 'removebreaks');
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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