Skip to content

[WordPress] Use PHP Program To Edit A Specific Page Content

Many different themes provide many different function page, some page have pretty UI and surprise function, but if you check their content in wp-admin, you will find the page content is blank!

I can not guarantee its implementation will be exactly as noted in this article, but one possibility is that it modifies specific pages by writing some PHP functions.

You can refer the references link I attached at the end to implement a simple WordPress plugin, or even edit the theme functions.php file.


How to use PHP to edit the page content

The method is very simple, it is using the hook provided by WordPress. We judge the page title in the page content, assuming that the page title is the same as we want (in the case, Test Page), then we can modify the content in $content.

// Try to edit the specific page
add_filter( 'the_content', 'change page_content' );

function change_page_content( $content ) {
    if ( get_the_title() == 'Test Page' ) {
        $content = '<p> Hello! This is the page that you can change the content</p>';
    }

    return $content;
}


We can see that in the background, the article is blank.


However, as soon as you go to the website to look at it, you will immediately find that there are more words that we define.


In addition to confirming the title, there are also different ways to confirm the article ID, article slug, etc. You can try it out.


References


Read More

Leave a Reply