Related posts at the last position in the content.
This file contains 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 | |
/** | |
* Add related posts at the last position in the content. | |
* URL to Plugin: https://de.wordpress.org/plugins/wordpress-23-related-posts-plugin/ | |
* | |
* @param string $content post content. | |
* | |
* @return string | |
*/ | |
function my_related_posts( $content ) { | |
$post_types = [ 'post' ]; | |
if ( ! function_exists( 'wp_related_posts' ) ) { | |
return $content; | |
} | |
if ( ! is_singular( $post_types ) ) { | |
return $content; | |
} | |
ob_start(); | |
wp_related_posts(); | |
$content .= ob_get_contents(); | |
ob_end_clean(); | |
return $content; | |
} | |
/* Apply filter for related posts */ | |
add_filter( 'the_content', 'my_related_posts', PHP_INT_MAX ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment