November 20, 2015

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’ );
else
$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

[wp_get_childpages]

Demo:

http://www.totalhindime.com/sabhi-pradesh-ki-government-job-search-aur-apply-kare/

You may also like...

Leave a Reply