How to show home page site content in wordpress post

If you want to display the content of your WordPress home page in a post, there are a few ways to achieve this depending on your specific needs. Here are three possible methods:

Use a shortcode:

You can create a shortcode that will output the content of your home page wherever you place it. Here are the steps to create the shortcode:

  • Open your theme’s functions.php file (Appearance > Theme Editor > functions.php).
  • Add the following code to create the shortcode:

function show_home_content_shortcode() {
return get_post_field(‘post_content’, get_option(‘page_on_front’));
}
add_shortcode(‘show_home_content’, ‘show_home_content_shortcode’);


This code retrieves the content of the page set as the front page of your website and returns it when the [show_home_content] shortcode is used.

  • Save the changes to the functions.php file.
  • In your post editor, enter the shortcode [show_home_content] where you want the home page content to appear.

Use a plugin:

You can also use a plugin like “Insert Pages” to insert your home page content into a post. Here’s how to do it:

  • Install and activate the “Insert Pages” plugin.
  • In your post editor, click the “Insert Pages” button above the editor.
  • Select “Home Page” from the dropdown menu and click “Insert”.
  • Save and publish your post.

Copy and paste:

Finally, you can simply copy the content from your home page and paste it into your post editor. This method may require some formatting adjustments to match your post’s styling.

Note that if your home page contains dynamic elements (like widgets or featured posts), these may not display correctly in a post using any of the above methods.

Where you can paste this code on functions.php

You can paste the code I provided in the functions.php file of your WordPress theme. The functions.php file is usually located in your theme’s directory, which you can access via your WordPress dashboard by going to Appearance > Theme Editor.

Once you are in the Theme Editor, you should see a list of files on the right-hand side of the screen. Look for the functions.php file and click on it to open it in the editor.

You can then paste the code I provided at the bottom of the file, right before the closing `?>` tag (if there is one).

It’s important to note that you should not paste this code in the header or footer of your website. The functions.php file is the appropriate place for this type of code, as it is specifically designed to hold PHP functions for your WordPress theme. Placing the code in the header or footer could cause issues with your website’s functionality.

If 1st code not work proper then use 2nd code

Here is an updated code snippet that should work:

function show_home_content_shortcode() {
$home_page = get_option(‘page_on_front’);
$home_content = get_post_field(‘post_content’, $home_page);
return apply_filters(‘the_content’, $home_content);
}
add_shortcode(‘show_home_content’, ‘show_home_content_shortcode’);


This code uses the `get_option` function to retrieve the ID of the page set as the home page, and then uses the `get_post_field` function to retrieve the content of that page. The `apply_filters` function is used to ensure that any WordPress filters applied to the home page content (such as those added by plugins) are also applied when the content is displayed in a post.

Please try replacing the previous code with this updated code and see if it works. Then you can add the `[show_home_content]` shortcode in your post editor to display the content of your home page.

More Question