Phi Ng Phi Ng - 1 month ago 9
PHP Question

Dynamically Insert page title into every page on Wordpress

I completed all page for my website on Wordpress.



For example.

The title 1: How to build a website on Wordpress

The title 2: How to secure a WP website



Now I want to add this line to all page at the bottom:

"If you have any question on [page title], please give a comment below!"



The result that I'm expecting should be:

Page 1 content:

Step 1

Step 2

If you have any question on How to build a website on Wordpress, please give a comment below!



Page 2 content

Step 1

Step 2

If you have any question on How to secure a WP website, please give a comment below!



How can I do that? Thanks

Answer

You can alter the page content by the the_content filter Have a look at the below code

add_filter( 'the_content', 'add_bottom_content' );
function add_bottom_content( $content ) {
    $content .=  "If you have any question on ".get_the_title().", please give a comment below!";
    return $content;
}