0

我正在尝试在 WordPress 主题上创建自定义 Facebook 分享按钮

<a title="Facebook This" href="http://www.facebook.com/sharer.php?s=100&p[title]=MY%20TITLE%20-%20<?php the_title(); ?>&p[summary]=<?php the_content(); ?>&p[url]=<?php the_permalink(); ?>&p[images][0]=<?php bloginfo('template_url'); ?>/images/logo.png" target="_blank">Facebook This</a>

除了 Facebook 坚持在描述中显示 HTML 字符外,我的一切工作都非常出色:

<h3>Intro</h3><p>it shows all the tags here and it won't stop!!!</p>...

它也使用 the_excerpt() 来做到这一点。

有谁知道为此删除html标签的快速方法?

4

3 回答 3

1

使用 Strip 标签,详情请访问: http ://php.net/manual/en/function.strip-tags.php

strip_tags(get_the_excerpt());
于 2012-09-18T09:24:27.463 回答
0

Saifuddin Sarker 的回答是一个很好的方法,另一种方法是:

wp_strip_all_tags( get_the_excerpt() );

于 2014-04-14T15:09:11.010 回答
0

在 the_content() 中转义 WordPress 的 HTML 字符;是使用:

ob_start();
the_content();

$old_content = ob_get_clean();

$new_content = strip_tags($old_content);

echo $new_content;
于 2016-06-16T00:12:03.703 回答