admin管理员组文章数量:1291616
My pages are all showing the Site Title (from the Customizer) after the page or post title and before the "body" of the post. Troubleshooting by injecting lines of text to print before and after WordPress code narrows the source down to the the_content()
call within the page template.
Here's how the_content()
is called:
...
</header><!-- .entry-header -->
<div class="content entry-content">
<?php the_content(
// Translators: %s: Name of current post. Only visible to screen readers.
sprintf( esc_html__( 'Continue reading %s', 'bulmapress' ), '<span class="screen-reader-text">' . the_title( '', '', false ) . '</span>' )
);
wp_link_pages( array(
'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'bulmapress' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->
<footer class="content entry-footer">
...
I'm a bit baffled because post_template.php
where the_content()
and get_the_content()
are defined is a WordPress /includes file, not a parent theme file.
Should I be looking for some filter that's been defined in the theme? TIA
My pages are all showing the Site Title (from the Customizer) after the page or post title and before the "body" of the post. Troubleshooting by injecting lines of text to print before and after WordPress code narrows the source down to the the_content()
call within the page template.
Here's how the_content()
is called:
...
</header><!-- .entry-header -->
<div class="content entry-content">
<?php the_content(
// Translators: %s: Name of current post. Only visible to screen readers.
sprintf( esc_html__( 'Continue reading %s', 'bulmapress' ), '<span class="screen-reader-text">' . the_title( '', '', false ) . '</span>' )
);
wp_link_pages( array(
'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'bulmapress' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->
<footer class="content entry-footer">
...
I'm a bit baffled because post_template.php
where the_content()
and get_the_content()
are defined is a WordPress /includes file, not a parent theme file.
Should I be looking for some filter that's been defined in the theme? TIA
Share Improve this question edited May 28, 2021 at 23:02 Rickmakeitquick asked May 28, 2021 at 20:35 RickmakeitquickRickmakeitquick 1431 silver badge13 bronze badges 3 |1 Answer
Reset to default 2The culprit was within an add_filter function. Commenting out the following removed the site title from above the page/post content:
function add_post_content($content) {
if(!is_feed() && !is_home()) {
$content .= '<p>This article is copyright © '.date('Y').' '.bloginfo('name').'</p>';
}
return $content;
}
add_filter('the_content', 'add_post_content');
The first part, "This article is copyright (c)", printed where you'd expect, but bloginfo('name') was appearing before the rest of the content.
Edit -- explanation:
In the WordPress Code Reference, some cryptic advice appears: "This always prints a result to the browser. If you need the values for use in PHP, use get_bloginfo()." Bloginfo()
consists of an echo
statement, so it prints to the browser immediately while the code is being pre-processed.
My call to bloginfo()
within a function in my child theme's functions.php
was processed before WordPress had a chance to print the page's or post's content, so that's when the output of the function appeared. Instead, get_bloginfo()
only returns the data corresponding to the requested argument.
本文标签: thecontent() printing site title after pagepost title and before its content
版权声明:本文标题:the_content() printing site title after pagepost title and before its content 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741531894a2383802.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
esc_html__
in the first param ofsprintf
might lead to unexpected results, I think. Try removing that, or moving it to the second parameter. – vancoder Commented May 28, 2021 at 20:39add_filter(
in the parent theme. There are two, and neither has anything to do with the site title. – Rickmakeitquick Commented May 28, 2021 at 20:42