简体   繁体   中英

how to add a static text on the blog list page of wordpress?

so, i created a child theme from oceanWP.

i decided to add in my 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' prints out twice though...... cause of the echo. without the echo, nothing prints out.

im thinking it gets hidden or immediately goes away?

wpbf_main_content_open is not a native Wordpress hook, it seems to be a hook from the Page Builder Framework. Do you use the Page Builder Framework?

However, that what you want can be done with native functions.

Action Hook 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>';
    }

}

Another way is the Custom Blog Posts Index Page Template . Make a copy from the page.php (or home.php if exists in the Parent-Theme) and save it as home.php in your Child-Theme. Then you can add the static text to this template (before the lopp starts).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM