Created
January 8, 2014 09:19
-
-
Save kovshenin/8313977 to your computer and use it in GitHub Desktop.
Append a link to the page parent at the end of the content when on children pages.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Page Parent Link | |
*/ | |
function my_the_content( $content ) { | |
$post = get_post(); | |
if ( 'page' == $post->post_type && $post->post_parent > 0 ) { | |
$parent = new WP_Query( array( | |
'post_type' => 'page', | |
'post__in' => array( $post->post_parent ), | |
) ); | |
if ( $parent->have_posts() ) { | |
$parent->the_post(); | |
$content .= sprintf( '<p><a href="%s">← %s</a></p>', get_permalink(), get_the_title() ); | |
} | |
wp_reset_postdata(); | |
} | |
return $content; | |
} | |
add_filter( 'the_content', 'my_the_content' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment