Display user HTML on website

时间:2015-12-31 作者:Michael

我在Wordpress中有一个设置页面,允许管理员输入HTML代码。我想使用一个快捷码在网站上的特定页面上显示此代码。

我现在的问题是,短代码显示HTML而不是执行它:

enter image description here

以下是我的功能:

function MKWD_Display_Westmor_Bottom_Left() {
  $westmor_customers_options = get_option( \'westmor_customers_option_name\' );
  return $westmor_customers_options[\'homepage_bottom_left_widget_0\'];
}
我做错了什么?

1 个回复
最合适的回答,由SO网友:jgraup 整理而成

您可能需要取消对输出的转义。看看html_entity_decode 或类似功能,然后再输出到屏幕。

$orig = "I\'ll \\"walk\\" the <b>dog</b> now";

$a = htmlentities($orig);

$b = html_entity_decode($a);

echo $a; // I\'ll &quot;walk&quot; the &lt;b&gt;dog&lt;/b&gt; now

echo $b; // I\'ll "walk" the <b>dog</b> now
<小时>html_entity_decode

function MKWD_Display_Westmor_Bottom_Left() {
  $westmor_customers_options = get_option( \'westmor_customers_option_name\' );
  return html_entity_decode ( $westmor_customers_options[\'homepage_bottom_left_widget_0\'] );
}
<小时>

htmlspecialchars_decode

function MKWD_Display_Westmor_Bottom_Left() {
  $westmor_customers_options = get_option( \'westmor_customers_option_name\' );
  return htmlspecialchars_decode ( $westmor_customers_options[\'homepage_bottom_left_widget_0\'] );
}
<小时>

wp_specialchars_decode

function MKWD_Display_Westmor_Bottom_Left() {
  $westmor_customers_options = get_option( \'westmor_customers_option_name\' );
  return wp_specialchars_decode ( $westmor_customers_options[\'homepage_bottom_left_widget_0\'] );
}
<小时>

stripslashes

function MKWD_Display_Westmor_Bottom_Left() {
  $westmor_customers_options = get_option( \'westmor_customers_option_name\' );
  return stripslashes ( $westmor_customers_options[\'homepage_bottom_left_widget_0\'] );
}