Basically I have a WordPress loop and I need all the code to be compressed and all unnecessary white-space to be stripped like so:
<article><p>Content</p></article><article><p>Content</p></article><article><p>Content</p></article>
I am including the loop file using:
<?php get_template_part('library/inc/loop'); ?>
Just wondering if there is a simple way like:
<?php trim( get_template_part('library/inc/loop') ); ?>
If this is possible all my problems would be solved, any help is much appreciated. Cheers!
To remove all leading and trailing whitespaces within HTML elements, you might use
// Remove whitespace before '<'
$html = preg_replace('~\s+<~', '<', $html);
// Remove whitespace after '>'
$html = preg_replace('~>\s+~', '>', $html);
This will leave any whitespace within text intact.
I'm not too familiar with the "back end" of WordPress, however you could try
str_replace(" ","",$data);//Find whitespace " " and replace with ""
To clarify: whitespace when outputting, or whitespace in the source code?
Or as you put try using trim(). I hope this helps you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.