快速概览: 我试图让页面标题显示在 the_content() 中,但这需要有条件,并且仅在页面有附加图像时显示。这也需要通过函数文件来完成。
我在哪里: 这是我到目前为止的代码......但它不起作用,我认为问题在于它在循环之外......我如何使用代码来查找页面ID。 ..或者我怎样才能让它工作?
<?php
if ( has_post_thumbnail() ) {
add_filter('the_content', 'contentTitle');
function contentTitle($content='')
{
$theTitle = '<h1>' . get_the_title() . '</h1>';
return $theTitle . $content;
}
} else {
// Do nothing
}
?>