Make WordPress Efficient Related Posts plugin show no output at all


Efficient Related Posts plugin for WordPress is, as it says, efficient — in finding related posts, but not that efficient in terms of presentation.

One important problem is that, even if there are no related posts to be displayed, and you have configured the plugin to display nothing in that case, still Efficient Related Posts will output a Related Posts header followed by an empty list, even starting with a bullet!

Perhaps the author of the plugin will do something in the future, but until that happens, you can tweak the plugin easily and safely.

You need to change two parts, one for the list / bullet, and another one for the header. First open in the Notepad the file efficient-related-posts.php At about line 291 you will encounter this code:

[sociallocker message=”Share, and keep reading!”]

if ( empty($relatedPosts) || $settings['num_to_display'] == 0 ){
/**
* @todo The before and after setting should apply to this too
*/
$output .= "<li>{$settings['no_rp_text']}</li>";

Just remove the <li>st elements; the code shoud become:

if ( empty($relatedPosts) || $settings['num_to_display'] == 0 ){
/**
* @todo The before and after setting should apply to this too
*/
$output .= "{$settings['no_rp_text']}";

Then at about line 319 you find:

/**
* @todo Make a before and after setting for this
*/
$output = "<ul class='related_post'>{$output}</ul>";

if ( !empty($settings['title'])  ) {
$output = "<h3 class='related_post_title'>{$settings['title']}</h3>{$output}";

Just add this to the condition: && !empty($relatedPosts)
Your code should become:

/**
* @todo Make a before and after setting for this
*/
$output = "<ul class='related_post'>{$output}</ul>";

if ( !empty($settings['title'])  && !empty($relatedPosts) ) {
$output = "<h3 class='related_post_title'>{$settings['title']}</h3>{$output}";

Enjoy a cleaner and more professional output from the Efficient Related Posts plugin!

1 Response

  1. Adam Farrah says:

    This helped me a lot! I was getting a blank “related posts” on a sales page.

    Thanks very much for this!

    Adam