WordPress get_the_content()无法显示文章代码高亮和图片暗箱

Gavin Wu 2022年05月11日 8:05 Wordpress 753 Views

WordPress get_the_content()无法显示文章代码高亮和图片暗箱|微言心语
最近,出现wordpress文章页的代码高亮和图片暗箱不显示了,经查看网页原代码发现,图片没有被自动添加fancybox标签详见《wordpress 添加fancybox图片暗箱》。来回翻查了好几遍,发现是因为我不想文章内容输出 有p标签,就将single.php里的the_content()修改为了get_the_content(),这对输出文字和图片内容没有问题,但在function.php里添加的a属性标签已经不起作用了。代码高亮插件codecolorer估计也是同样的问题。果然将single里的get_the_content()改回the_content()后问题解决了。
后来查看wordpress文档发现get_the_content()里有这样一句话

An important difference from is that does not pass the content through the filter. This means that will not auto-embed videos or expand shortcodes, among other things.the_content()get_the_content()the_contentget_the_content()

原文传送门:https://developer.wordpress.org/reference/functions/get_the_content/
英文不好,重点大概意思是不会传递函数和视频、扩展短代码!
附上在不修改the_content的情况去掉文章内的p标签的方法

1
2
//wordpress摘要去掉p标签
remove_filter('the_content', 'wpautop');

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

Top