Skip to content

Instantly share code, notes, and snippets.

@pixelbart
Last active July 15, 2019 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pixelbart/1315bd54568ac98927d3e4b82befad32 to your computer and use it in GitHub Desktop.
Save pixelbart/1315bd54568ac98927d3e4b82befad32 to your computer and use it in GitHub Desktop.
Related posts at the last position in the content.
<?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