WordPress通过过滤器删除the_title?
问题描述:
我需要删除下面的代码这是我的WordPress模板中发现: <?php the_title('<h1 class="entry-title">', '</h1>'); ?>
WordPress通过过滤器删除the_title?
我不想修改模板或通过CSS做到这一点。
我想通过functions.php文件以某种方式做到这一点。
也许是这样的: add_filter('the_title', 'suppress_if_title_h1', 10, 2);
我只是不知道下一步该怎么做?
有什么建议吗?
答
我没有错,你想从你的模板文件中删除这个<?php the_title('<h1 class="entry-title">', '</h1>'); ?>
代码。
是的,您可以使用wp过滤器通过功能文件从模板中删除下面的代码。写一个函数像下面 -
function remove_post_title ($title, $id = null) {
// This will remove the title from the post
return '';
}
add_filter('the_title', 'remove_post_title', 10, 2);
+0
检查食品:https://codex.wordpress.org/Plugin_API/Filter_Reference/the_title - 你不会有它是否是一个H1,类等 –
访问有没有办法确定是否是H1,H2等? – Aaron
正确。过滤器对标记没有“洞察力”,所以没有实用的方法。如果您好奇,请查看'wp-includes/post-template.php'中'the_title'函数的代码。唯一被过滤的是实际标题,而不是标记($ before/$ after之后)。 –