Create your own shortcode in wordpress

Its very easy to Create your own shortcode in wordpress. Simply follow this code and copy from here to your wordpress function.php placed at the theme directory.

This will create shortocde [wp_get_childpages] that is attached with a function  wp_get_list_child_pages()

function wp_get_list_child_pages() {

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’ );
$childpages = wp_list_pages( ‘sort_column=menu_order&title_li=&child_of=’ . $post->ID . ‘&echo=0’ );

if ( $childpages ) {

$string = ‘<ul>’ . $childpages . ‘</ul>’;

return $string;


add_shortcode(‘wp_get_childpages’, ‘wp_get_list_child_pages’);

Use this in a content page as



Leave a Comment