How to trim leading and trailing spaces from output

<Loop type="dogs" id="{Get local=pid}">
  <Field breed />

That template works great, except it returns with leading and trailing spaces. How would I trim them? (dogs is a CPT and breed is an ACF)

Cheers, Richard

Hey Richard! As far as I can tell, the addition of leading and trailing spaces seems to just be normal behaviour when writing HTML when you add line breaks. If you just added a normal WP custom HTML block to your page, the following markup would create spaces between the hyphens:

<a href="">something</a>

Whereas when you write it inline, there are no spaces between the hyphens:

-<a href="">something</a>-

So for your example, you’d just need to write it something like:

This dog's breed is "<Loop type="dogs" id="{Get local=pid}"><Field breed /></Loop>"

Thanks so much for responding. Seems like I should have known that. I think where I have run into this before in php I just used a trim() function.

I’m using this inside the custom layout html of a beaver builder posts module which won’t let me use <loop … > etc.

However I can use a shortcode to a template, and putting the template all on one line makes it work.

Thanks again. Richard

Glad I could help! Since you’re working with custom Beaver Builder modules, you might be interested in checking out Tangible Blocks which allows you to create your own BB modules with custom controls using L&L markup.

1 Like