Last Updated on 2022-02-12 by Clay
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
- https://wordpress.stackexchange.com/questions/112858/output-the-title-inside-the-content
- https://wordpress.stackexchange.com/questions/12684/what-params-are-available-with-the-content-filter
Read More
- [Solved] Parse error: syntax error, unexpected ''lists_page'' (T_CONSTANT_ENCAPSED_STRING), expecting ')' in /var/www/html/wp-content/plugins/reserve-course/reserve-course.php on line 54
- [Solved] Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'change page_content' not found or invalid function name in