Fix HTML entities escaping problem of WP-Syntax

Problem

In WordPress, to make the posts more user friendly, I installed WP-Syntax to highlight the syntax of the code in my posts. However, the HTML entities like “&lt;” cannot be displayed correctly. And it is shown as the original HTML code “&lt;” instead of “<“.

Reason

GeSHi converts the HTML special chars to HTML entities with its own hcs() function.

Solution 1 – Recommended

In latest version of WP-Syntax, there is a parameter “escaped” can help to do this.

<pre lang="php" escaped="true">...</pre>

Solution 2 – Old versions

Modify the WP-Syntax plugin directly. Change below line

$geshi = new GeSHi($code, $language);

To

$geshi = new GeSHi(htmlspecialchars_decode($code), $language);

Reference

Escaping problem with WP-Syntax WordPress plugin

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理

Back to Top