Dynamically add about page content to a page in WordPress.

Today I’m going to show you how to grab your about page content and display it on your WordPress page. If you haven’t already created your about page, go to pages in your wordpress dashboard and add a new page called about. Now add some text and publish that page.


Open your functions php file and insert the following code anywhere in your file:

<!--?php -->/*******************************


 <!--?php content('20'); ?-->

function content($num) {
$theContent = get_the_content();
$output = preg_replace('/]+./','', $theContent);
$output = preg_replace( '/<blockquote>.*</blockquote>/', '', $output );
$output = preg_replace( '|[(.+?)](.+?[/\1])?|s', '', $output );
$limit = $num+1;
$content = explode(' ', $output, $limit);
$content = implode(" ",$content)."...";
echo $content;

All this code is basically doing is grabbing the content from the page, replacing any weird characters and finally setting the limit of characters to show from the about page content.

Page ID

To find out the page id of the about page, go to permalinks in your wordpress dashboard menu and change the permalink structure to default. Now open the about page in a browser and it should tell you the page id.


PHP code

Within the file you want the about page content to appear, add in the following code:

<!--?php query_posts('page_id=47'); 	if (have_posts()) : ?-->
		<!--?php while (have_posts()) : the_post(); ?-->
		<!--?php echo content('20'); endwhile; ?-->
	<!--?php endif; ?-->

Here we grab the page id of the about page and then we check if there is some content on the about page. The content(’20′) means that the text block will display 20 characters from the about page.



If all went well you now should have your about page content on your page!
I hope you enjoyed this little tutorial, don’t forget to leave a comment below or share this article with your friends.