Displaying Child Pages on the Parent Page in WP with a shortcode
To display child pages on a parent page in WordPress just edit theme’s functions.php file and and the following code:
global $post; if ( is_page() && $post->post_parent ) $childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->post_parent . '&echo=0' ); else $childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->ID . '&echo=0' ); if ( $childpages ) { $string = '</code> <ul>' . $childpages . '</ul> '; } return $string; } add_shortcode('wpb_childpages', 'wpb_list_child_pages');
Then add the [wpb_childpages]
shortcode wherever you need to display child pages. ;)
If you need to Display Child Pages Without Any Shortcode dinamically, you need to add this line of code where you want to display child pages:
The theme will now automatically detect child pages and display them.
- WordPress Security – Why Updates and Security Measures are Crucial? - 19 March 2023
- WordCamp Poland 2023 Gliwice – WordPress user conference - 28 February 2023
- How do I restore a previous version of WordPress when an update has failed? - 9 January 2023