Wordpress 3 - 通过 functions.php 从帖子中删除链接 [英] Wordpress 3 - Remove Links from Posts via functions.php
问题描述
有没有办法通过我的functions.php文件删除帖子中的链接.基本上我不希望任何人能够离开所查看的博客文章.我有数百个帖子,所以我显然无法浏览所有帖子并手动删除它们.或者我可以使用javascript吗?
Is there a way that I can remove links in posts via my functions.php file. Basically I don't want anyone to be able to go outside of the blog posts that are viewed. I have hundreds of posts so I obviously can't go through all of them and remove them manually. Or could I use javascript?
非常感谢.
更新:下面的 jQuery 很棒.有谁知道我是否可以通过我的functions.php 文件中的php 做到这一点?如果出于任何荒谬的原因,有人禁用了 JS,这就是我问的原因.
Updated: The jQuery below is great. Does anyone know if there is a way I can do it thru php in my functions.php file? If, for whatever ridiculous reason, someone has JS disabled is why I ask.
谢谢!
推荐答案
您可以使用 JavaScript,但如果人们愿意,您将无法阻止他们离开.
You could use JavaScript, but you're not going to be able to stop people leaving if they want to.
这样的东西可能有用,虽然我还没有测试过,而且是随手写的:
Something like this may work, although I haven't tested and it was written off-hand:
<script>
$('#content a').each(function() {
$(this).replaceWith($(this).text());
});
</script>
使用 jQuery 库,这应该替换所有 标签以及它们之间的内容.
With the jQuery library, this should replace all <a>
tags with what was in between them.
所以 <a href="http://www.google.co.uk/">Google</a>
应该只是 Google
.
这篇关于Wordpress 3 - 通过 functions.php 从帖子中删除链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!