我习惯于通过可视化编辑器在帖子中添加javascript/jquery代码,但似乎我从未使用过&&;操作员原因wordpress正在更改(&P)&;&;中的运算符;。以下是我正在使用的链接&&;。http://demo.techstriders.com/corey/canyon/calculator/我想知道在wordpress可视化编辑器中使用javascript的正确方法是什么。
可视化编辑器中的JavaScript&运算符
1 个回复
最合适的回答,由SO网友:birgire 整理而成
您应该使用wp_enqueue_script 而不是将代码直接添加到帖子内容中。
ps:您可以在the_content
过滤器,使用
add_action(\'wp_footer\',function(){
global $wp_filter;
printf(\'<pre>%s</pre>\',print_r( $wp_filter[\'the_content\'],true));
});
在主题的页脚部分显示它们。然后您将看到如下回调wpautop
, wptexturize
, convert_chars
和convert_smilies
.我不建议这样做,但可以删除这些过滤器,以便在帖子内容中使用javascript代码:
add_action(\'init\',\'custom_init\');
function custom_init() {
remove_filter(\'the_content\', \'wpautop\');
remove_filter(\'the_content\', \'wptexturize\');
remove_filter(\'the_content\', \'convert_chars\');
remove_filter(\'the_content\', \'convert_smilies\');
}
结束