Jump to content

Removing line breaks


V

Recommended Posts

Well it all depends on what the function does.

 

Does it echo or return the statement as a value? Given that it does not have an echo preceding it, I am taking that it echos. And because of this you would either need to use output buffering, change the function to return a value, or add a parameter to tell it to echo it without line breaks. (via an if statement).

I'm trying to implement a php code in a Wordpress site to remove line breaks from excerpts. I suspect str_replace will work but I'm not sure how to use it with a function..

 

<?php the_excerpt(); ?>

 

i think you havta use javascript on this one. This echos it, not returns it

 

anyone have any idea?

 

 

As premiso said, it depends. If it returns the excerpt something like this will do:

 

echo str_replace("\n", '', the_excerpt());

 

If it echos the excerpt something like this will work:

 

ob_start();
the_excerpt();
echo str_replace("\n", '', ob_get_clean());

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.