如何在wordpress的博客列表页面添加静态文本?
how to add a static text on the blog list page of wordpress?
所以,我从 oceanWP 创建了一个子主题。
我决定加入我的 functions.php.....
function echo_comment_id( $comment_id ) {
if ( is_home() ){
$content = 'hi there';
echo $content;
}
return $content;
}
add_action( 'the_content', 'echo_comment_id', 10, 1 );
my 'hi there' 虽然打印了两次......回声的原因。
没有回声,什么也打印不出来。
我认为它会被隐藏或立即消失?
wpbf_main_content_open
不是原生的 Wordpress 挂钩,它似乎是来自 Page Builder Framework 的挂钩。您使用 Page Builder Framework 吗?
但是,您想要的可以使用本机函数完成。
动作挂钩loop_start
// place this in your functions.php
add_action( 'loop_start', 'add_static_text_on_blog_list_page' );
function add_static_text_on_blog_list_page( ) {
// Check if this is the Blog-Post-Page and main query.
if ( is_home() && is_main_query() ) {
echo '<h1>Hey everyone!</h1><p>This is a quick intro.</p>';
}
}
另一种方式是Custom Blog Posts Index Page Template。从 page.php
(或 home.php
,如果 Parent-Theme 中存在)复制一份,并将其另存为 home.php
在您的 Child-Theme 中。然后您可以将静态文本添加到此模板(在 lopp 开始之前)。
所以,我从 oceanWP 创建了一个子主题。
我决定加入我的 functions.php.....
function echo_comment_id( $comment_id ) {
if ( is_home() ){
$content = 'hi there';
echo $content;
}
return $content;
}
add_action( 'the_content', 'echo_comment_id', 10, 1 );
my 'hi there' 虽然打印了两次......回声的原因。 没有回声,什么也打印不出来。
我认为它会被隐藏或立即消失?
wpbf_main_content_open
不是原生的 Wordpress 挂钩,它似乎是来自 Page Builder Framework 的挂钩。您使用 Page Builder Framework 吗?
但是,您想要的可以使用本机函数完成。
动作挂钩loop_start
// place this in your functions.php
add_action( 'loop_start', 'add_static_text_on_blog_list_page' );
function add_static_text_on_blog_list_page( ) {
// Check if this is the Blog-Post-Page and main query.
if ( is_home() && is_main_query() ) {
echo '<h1>Hey everyone!</h1><p>This is a quick intro.</p>';
}
}
另一种方式是Custom Blog Posts Index Page Template。从 page.php
(或 home.php
,如果 Parent-Theme 中存在)复制一份,并将其另存为 home.php
在您的 Child-Theme 中。然后您可以将静态文本添加到此模板(在 lopp 开始之前)。