Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Linebreaks as BR from page content?
#1
Is there a way to enable parsing of linebreaks from page content as <BR > in output html?


In the template I tried changing:

Code:
<?php get_page_content(); ?>

to

Code:
<?php nl2br( get_page_content() ); ?>

without success Sad

Thanks
Reply
#2
Here's one way to do it, by creating a modified copy of GS's get_page_content() function.

Create a functions.php file in your theme folder (or edit it if exists), and insert this:

Code:
<?php
function get_page_content_nl2br() {
    global $content;
    exec_action('content-top');
    $content = strip_decode($content);
    $content = nl2br(exec_filter('content',$content));
    echo $content;
    exec_action('content-bottom');
}

Now edit your template file and change:
Code:
<?php get_page_content(); ?>
to:
Code:
<?php get_page_content_nl2br(); ?>
Reply
#3
You are awesome, Carlos!

Thanks a lot, I implemented your code and it works 'out of the box'.
Reply
#4
There's an easier way, by making a small plugin that calls add_filter()
(Later...)
Reply
#5
Here's the better solution, a plugin. Save next lines into a file, name it nl2br.php

Code:
<?php

$thisfile = basename(__FILE__, ".php");

register_plugin(
    $thisfile, 'nl2br', '0.1', 'Carlos', '#',
    'Convert line breaks to &lt;br /&gt;', '', ''
);

add_filter('content',nl2br);
Upload nl2br.php to your plugins folder.

This plugin doesn't require editing your template, nor having a functions.php file in your theme.

(BTW, before trying this plugin you should undo changes by my previous suggestion.)
Reply




Users browsing this thread: 1 Guest(s)