本文介绍了如何包含“onclick” WordPress HTML中的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用试图将onclick对象添加到触发事件的单点(而不是多点)WordPress的页面。代码是:

 < a href =#onclick =_ speakpipe_open_widget(); return false;>发送语音消息< / a> 

当试图保存代码时,WordPress剥离了onclick对象:

 < a href =#>发送语音留言< / a> 

另一个论坛上的用户,此限制只适用于多站点非超级用户。同样,这是一个只有一个管理员用户的签证。



据了解,WordPress从HTML中删除onclick以防止恶意代码。仍然有人知道如何解决这个问题吗?

谢谢。

通过解析,我假设你的意思是允许onclick属性。您需要注意这一点,因为修改允许的标签会为您的所有用户执行此操作。



您可以修改允许的标签和属性列表到你的functions.php文件:

pre $ function allow_onclick_content(){
global $ allowedposttags,$ allowedtags;
$ newattribute =onclick;

$ allowedposttags [a] [$ newattribute] = true;
$ allowedtags [a] [$ newattribute] = true; //不必要?
}
add_action('init','allow_onclick_content');

我建议先用$ allowedposttags先试试看看它是否适用于您。根据此,如果您需要,您应该只需要allowedtags对于评论或可能未登录的用户,但是当我过去做了类似的事情时,我需要他们两个人的工作。



在旁注中,if你想要一个所有已经允许的标签和属性列表,看看你的。


I'm using attempting to add an "onclick" object to a page in a singlesite (i.e. rather than multisite) WordPress that triggers an event. The code is:

<a href="#" onclick="_speakpipe_open_widget(); return false;">Send a voice message</a>

When attempting to save the code, WordPress strips the onclick object leaving:

<a href="#">Send a voice message</a>

A user on another forum suggested that this restriction should only apply to multisite non-superadmin users. Again, this is a siglesite with only one admin user.

It is understood that WordPress removes "onclick" from HTML to prevent malicious code. Still, does anyone know how to resolve this?

Thanks.

解决方案

By resolving, I'm assuming you mean to allow the onclick attribute. You will want to be careful with this, because modifying the allowed tags does this for all your users.

You can modify the list of allowed tags and attributes, by adding this to your functions.php file:

function allow_onclick_content() {
  global $allowedposttags, $allowedtags;
  $newattribute = "onclick";

  $allowedposttags["a"][$newattribute] = true;
  $allowedtags["a"][$newattribute] = true; //unnecessary?
}
add_action( 'init', 'allow_onclick_content' );

I suggest trying it with only $allowedposttags first to see if that works for you. According to this other stackexchange post, you should only need allowedtags if you need it for comments or possibly non-logged-in users, but when I did something similar in the past, I needed both of them to work.

On a side note, if you want a list of all already allowed tags and attributes, look inside your /wp-includes/kses.php file.

这篇关于如何包含“onclick” WordPress HTML中的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 20:40