I create a custom plugin that has a wp_editor
on the admin, now when I put some html tags in the editor in Text
view tab like <br>
and click on the Visual
tab.. the <br>
converts into <p> </p>
when I back to Text
tab.
this is my php code:
$html_value = '<h1>test</h1><br> ....';
$settings = array( 'textarea_name' => 'al_srms_fileform_content', 'media_buttons' => true, 'wpautop' => false );
wp_editor($html_value, 'mycustomeditor0pdf', $settings );
this is what happening:
I put <br>
tag by Text
tab.
I click Visual
to display the result.
I click back the Text
tab and the <br>
is gone and replaced by <p> </p>
is there a way the when putting a <br>
it remains <br>
?
I hope this will assist you. You don’t need to install the suggested plug-in, though. Just add this mini plugin and you’re set:
Now when you press enter,
<br>
tag will be inserted instead of creating new paragraph. But beware, if you create two consecutive newlines, the text will still be split to paragraph as a result of wpautop filter applied to your post content. You need to remove this filter first and create a new filter that will replace all newlines with<br>
tags. Add something like this to your functions.php to display the<br>
tags in your template:The problem you are running into is the result of the wpautop filter function in your Themes functions.php file.
To disable this function add the following to lines to your functions.php file located in your themes directory:
Reference: https://codex.wordpress.org/Function_Reference/wpautop (WordPress Codex)