2015-10-07 113 views
2

我創建對管理員,一個wp_editor自定義插件現在,當我把一些html標籤在編輯器中Text查看標籤像<br>,然後單擊Visual選項卡上。該<br>當我回到Text選項卡時,轉換爲<p>&nbsp;</p>wp_editor總是轉換<br>到<p> </p>

這是我的PHP代碼:

$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); 

這是什麼情況發生: 我把<br>標籤由標籤Textenter image description here

我點擊Visual顯示結果。 enter image description here

我點擊回Text標籤和<br><p>&nbsp;</p> enter image description here

不見了,取而代之的則是那裏把一個<br>時保持<br>的方法嗎?

+0

我有同樣的確切的問題...但似乎沒有正確的答案嗎?令人沮喪。 – Zak44

回答

0

您遇到的問題是主題functions.php文件中的wpautop過濾器功能的結果。

要禁用此功能,添加以下行位於你的主題目錄下的functions.php文件:

remove_filter('the_content', 'wpautop'); 
remove_filter('the_excerpt', 'wpautop'); 

參考:https://codex.wordpress.org/Function_Reference/wpautop(WordPress的法典)

+0

感謝邁克,我試過了,但它不工作 – gadss

0

我希望這會幫助你。不過,您不需要安裝建議的插件。只需添加這個小插件,你設置:當你按下輸入

<?php 
defined('ABSPATH') OR exit; 
/* Plugin Name: TinyMCE break instead of paragraph */ 
function mytheme_tinymce_settings($tinymce_init_settings) { 
    $tinymce_init_settings['forced_root_block'] = false; 
    return $tinymce_init_settings; 
} 
add_filter('tiny_mce_before_init', 'mytheme_tinymce_settings'); 

現在,<br>標籤將被插入,而不是建立新的段落。但請注意,如果您創建了兩個連續的換行符,則由於將wpautop過濾器應用於您的發佈內容,文本仍會被拆分爲段落。您需要先刪除此過濾器並創建一個新的過濾器,用<br>標籤替換所有換行符。加入這樣的事情你的functions.php,以顯示你的模板<br>標籤:

remove_filter ('the_content', 'wpautop'); 
add_filter ('the_content', 'add_newlines_to_post_content'); 
function add_newlines_to_post_content($content) { 
    return nl2br($content); 
} 
相關問題