Skip to content

Instantly share code, notes, and snippets.

@pixelbart

pixelbart/functions.php

Last active Jul 15, 2019
Embed
What would you like to do?
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
You can’t perform that action at this time.