WordPress帖子中的JavaScript [英] JavaScript in a WordPress post
问题描述
如何添加
<a href="javascript:function foo(){alert('hi');}" title="alert">
Drag to your bookmarks bar
</a>
我的WordPress帖子?
to my WordPress post?
我建立了一个书签,我想通过我的博客传递它,但是当我保存它时,WordPress正在从我的帖子中删除javascript.
I built a bookmarklet and I want to pass it through my blog, but WordPress is stripping out the javascript from my post when I save it.
推荐答案
我猜想wordpress编辑器用于处理文本数据/内容.因此,要添加您的js,您可以找到用于添加自定义js的插件.您也可以在帖子中添加自定义"字段.
I guess that wordpress editor is used to work with textual data/content. So, to add your js you can find plugin for adding custom js. Also you can add a Custom field to the posts.
让它成为"custom_js"; -包含js代码的字段的名称.然后编辑主题后模板,在其中添加"echo" custom_js.
Let it be "custom_js" - the name of a field that would contain js code. And then edit theme post temlate, adding "echo" of custom_js.
<?php
//single.php
echo get_post_meta( get_the_ID(), 'custom_js');
?>
这篇关于WordPress帖子中的JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!