Please or Register to create posts and topics.

How can I add HTML code to the post editor

Page 1 of 2Next

I want to add some code snippets to the forum post. How can I do that?

me too

I have solved this problem, you need to install a code highlight plugin, or support the code highlight theme, in addition, the focus is [crossed, focus] if the theme inside the use of WordPress comes with the_content function, you may need to add the following The plugin is provided into the filter.
For example, my code is the theme of the code to prevent HTML escape

/*
 * 强制阻止WordPress代码转义,关于代码高亮可以看这里http://googlo.me/archives/2986.html
*/
function git_esc_html($content) {
    $regex = '/(<pre\s+[^>]*?class\s*?=\s*?[",\'].*?prettyprint.*?[",\'].*?>)(.*?)(<\/pre>)/sim';
    return preg_replace_callback($regex, 'git_esc_callback', $content);
}
function git_esc_callback($matches) {
    $tag_open = $matches[1];
    $content = $matches[2];
    $tag_close = $matches[3];
    //$content = htmlspecialchars($content, ENT_NOQUOTES, get_bloginfo('charset'));
    $content = esc_html($content);
    return $tag_open . $content . $tag_close;
}
add_filter('the_content', 'git_esc_html', 2);
add_filter('comment_text', 'git_esc_html', 2);

If you want the code to take effect inside the forum, you also need to add a line of code

add_filter('asgarosforum_filter_post_content', 'git_esc_html', 2);

 

 

Uploaded files:
  • TIM截图20171101113121.jpg
kanita88 has reacted to this post.
kanita88

that’s great, thanx

For adding code-snippets to forum posts I am using the Enlighter WordPress plugin. I am also using it in this support forum and its working very well.

If you want to support the development of Asgaros Forum, you can leave a good review or donate. Thank you very much!
Quote from Asgaros on November 2, 2017, 6:10 pm

For adding code-snippets to forum posts I am using the Enlighter WordPress plugin. I am also using it in this support forum and its working very well.

Why I am not seeing all these formatting buttons on my Asgaros forum? I am also finding it difficult to find Enlighter button added to the format bar. I have installed the plugin and selected enable for frontend still it is not showing.

Have you disabled the “Use minimalistic editor”-checkbox in the forum-settings?

If you want to support the development of Asgaros Forum, you can leave a good review or donate. Thank you very much!
Quote from Asgaros on January 20, 2018, 12:50 pm

Have you disabled the “Use minimalistic editor”-checkbox in the forum-settings?

No it is enabled, but disabling worked for me, thanks.

Quote from Asgaros on January 20, 2018, 12:50 pm

Have you disabled the “Use minimalistic editor”-checkbox in the forum-settings?

I have the same problem but I don’t find that checkbox in the forum settings…

I solved that by installing TinyMCE Advanced but I have now a display problem :
items in the menu of the message’s text editor are written in white on a white background, so does the window openning when I select “source code”…
My site has a black background and the default color for text is white, maybe this is why… but what can I do to change that for the text editor ?

Page 1 of 2Next