V Posted May 31, 2010 Share Posted May 31, 2010 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(); ?> anyone have any idea? Quote Link to comment https://forums.phpfreaks.com/topic/203445-removing-line-breaks/ Share on other sites More sharing options...
premiso Posted May 31, 2010 Share Posted May 31, 2010 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). Quote Link to comment https://forums.phpfreaks.com/topic/203445-removing-line-breaks/#findComment-1065819 Share on other sites More sharing options...
ohdang888 Posted May 31, 2010 Share Posted May 31, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/203445-removing-line-breaks/#findComment-1065821 Share on other sites More sharing options...
Alex Posted May 31, 2010 Share Posted May 31, 2010 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()); Quote Link to comment https://forums.phpfreaks.com/topic/203445-removing-line-breaks/#findComment-1065824 Share on other sites More sharing options...
V Posted May 31, 2010 Author Share Posted May 31, 2010 Thank you for the codes AlexWD For some reason they don't remove the <br> tags. Not sure if /n in the same but I tried using <br> in the code as well. Maybe I have to go into the wordpress function file and try from there. Quote Link to comment https://forums.phpfreaks.com/topic/203445-removing-line-breaks/#findComment-1065834 Share on other sites More sharing options...
Alex Posted May 31, 2010 Share Posted May 31, 2010 <br> is an html line break. If you wanted to remove those instead use: str_replace("<br>", '', ...); Or if you want to remove both literal and html line breaks: str_replace(array("\n", '<br>'), '', ...); Quote Link to comment https://forums.phpfreaks.com/topic/203445-removing-line-breaks/#findComment-1065836 Share on other sites More sharing options...
V Posted June 1, 2010 Author Share Posted June 1, 2010 I tried a bunch of codes, still no go.. I can't wait to learn php and ditch Wordpress lol Quote Link to comment https://forums.phpfreaks.com/topic/203445-removing-line-breaks/#findComment-1065931 Share on other sites More sharing options...
ohdang888 Posted June 1, 2010 Share Posted June 1, 2010 I tried a bunch of codes, still no go.. I can't wait to learn php and ditch Wordpress lol nah, i like wordpress. i dug around the source files and found this function: $myExcerpt = get_the_excerpt(); That should do it for ya Quote Link to comment https://forums.phpfreaks.com/topic/203445-removing-line-breaks/#findComment-1065940 Share on other sites More sharing options...
V Posted June 1, 2010 Author Share Posted June 1, 2010 Thanks ohdand! It work with that Yup Wordpress is cool but sometimes it really frustrates me. Quote Link to comment https://forums.phpfreaks.com/topic/203445-removing-line-breaks/#findComment-1066345 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.