Boost SEO with a Quick Shortcode to Display Page Children

We all know that the more links to a page the higher it shows in the search engines. This is also true internally. This is why it is very important to create a well organized interlinking structure. This can be slightly complicated, but here is a quick and dirty little trick you can use.

I wrote a quick shortcode to help generate all the children of a page. You can use this shortcode in any blog post or widget, and it will display all the children of a certain page. By default, it shows all the children of the current page, but you cna also specify which page it uses.

To use this code, place this code in your functions.php file:

// Adds Shortcode [display_children class="you_class" id="your_id" page_id="your_page_id"] (attributes are optional)
function display_children_func( $atts ) {
	$a = shortcode_atts( array(
		'class' => 'page_children',
		'id' => 'page_children',
		'page_id' => get_the_ID(),
	), $atts );
	$children = wp_list_pages('title_li=&child_of='.$a['page_id'].'&echo=0');
	if ($children) { 
		$output = '<ul class="'.$a['class'].'" id="'.$a['id'].'">'.$children.'</ul>';
	}
	else {
		$output = '';
	}
	return $output;
}
add_shortcode( 'display_children', 'display_children_func' );

That is it!

Now, all you have to do is use the short code.

You can simply add

[display_children]

Which will use the default class, id, and will display the current page’s children. If there are no children, it will display nothing. You can also specify your own class, id, and page id to use. Below is an example:

[display_children class="you_class" id="your_id" page_id="your_page_id"]

To get the page id from a page, simply edit that page and look at the url in the address bar. The page id is the number right after “post=”. For example, the post id for the following post is 79.

http://robertomejia.us/wp-admin/post.php?post=79&action=edit

Adding something like this will help search engines find all your pages, and will help them rank thos pages slightly higher.

Leave a comment

Your email address will not be published. Required fields are marked *