HI,欢迎来到我爱模板网!

the_content() 和 get_the_content() 的区别是什么?

the_content() 和 get_the_content() 的区别是什么?如果你是一名WordPress开发者,你可能知道WordPress函数the_content()可以直接输出文章内容,而get_the_content()则需要在前面添加echo才可以输出文章内容。<?phpthe_content(...

the_content() 和 get_the_content() 的区别是什么?如果你是一名WordPress开发者,你可能知道WordPress函数the_content()可以直接输出文章内容,而get_the_content()则需要在前面添加echo才可以输出文章内容。

<?phpthe_content();echo get_the_content();?>

这是WordPress内置函数的一个很重要的标志,the_开头的函数直接输出,get_开头的函数不执行输出。

然而,两者的区别不仅如此:

get_the_content()不会通过the_content传递内容 。这意味着它不会自动嵌入视频或扩展简码。所以,使用get_the_content(),它将删除嵌入和简码等标签。

get_the_content()获取的内容是原始保存的数据,不含段落标签p,导致原本应该分段的内容,无法进行分段。也即是说<?php echo get_the_content(); ?>和<?php the_content(); ?>输出的内容是不一样的,前者会过滤掉很多标签。所以,如果你要输出正文的完整内容时,请使用 <?php the_content(); ?>

最近折腾的项目就遇到这个问题,这次才搞明白<?php echo get_the_content(); ?>和<?php the_content(); ?>是真的不一样的。

the_content() 和 get_the_content() 的区别是什么? (https://www.wpmee.com/) WordPress开发教程 第1张

给TA打赏
共{{data.count}}人
人已打赏
wordpress教程

长沙wordpress企业网站开发大概多少钱

2023-2-17 0:02:01

wordpress教程

wordpress外贸网站的设计过于中式化

2023-2-17 0:02:02

【腾讯云】11.11云上盛惠!云服务器首年1.8折起,买1年送3个月!
11.11云上盛惠!海量产品·轻松上云!云服务器首年1.8折起,买1年送3个月!超值优惠,性能稳定,让您的云端之旅更加畅享。
查看更多相关信息>>
站长

(工作日 10:00 - 22:30 为您服务)

2026-01-30 04:16:56

您好,无论是售前、售后、意见建议……均可通过联系工单与我们取得联系。

猜你想问:

  • 购买的模板免费包安装吗?

  • 这个演示地址有吗?

  • 购买vip会员可以下载哪些模板?

您的留言我们已经收到,我们将会尽快跟您联系!
取消
立即选择任一渠道联系我们