Manually Adding nRelate Code To Your WordPress Template

If you want control exactly where nRelate displays on your website, you can manually insert our PHP function into your WordPress template, FUNCTIONS.PHP OR use our Shortcode in your actual Post or Page. It’s actually quite simple:

Manually Inserting PHP function into your THEME TEMPLATE:

  1. Pick the proper WordPress theme file to add your code.  For example you may pick SINGLE.PHP for single posts.
  2. Insert the proper nrelate code into the file, save and upload to your site:
    • RELATED CONTENT: 
      <?php if (function_exists('nrelate_related')) nrelate_related(); ?>
    • MOST POPULAR: 
      <?php if (function_exists('nrelate_popular')) nrelate_popular(); ?>

Manually Inserting PHP function into your FUNCTIONS.PHP FILE:
Plugins like nRelate (and most social plugins) automatically attach themselves to your post content. Use this code snippet in your FUNCTIONS.PHP file to control where nRelate shows up. Change both of the “99″s to any number between 0 and 999 to move nRelate. This is essentially a sort order for all plugins that attach themselves to your post content.

remove_filter( 'the_content', 'nrelate_related_inject', 10 );
remove_filter( 'the_excerpt', 'nrelate_related_inject', 10 );
add_filter( 'the_content', 'nrelate_related_inject', 99 );
add_filter( 'the_excerpt', 'nrelate_related_inject', 99 );

Using our Shortcode in your Post or Page:

  1. Edit the Post or Page you want to show nrelaate.
  2. Insert the proper nrelate shortcode into the body of the Post or Page:
    • RELATED CONTENT: 
      [nrelate-related]
    • MOST POPULAR: 
      [nrelate-popular]

Once you’ve completed the steps above, you now have to change some settings in your WordPress Admin:

  1. Scroll down the the LAYOUT SETTINGS area.
  2. Under “Which pages should display related content?“, check all the boxes where you want nrelate to display.  Just because you manually place the nRelate code in your SINGLE.PHP file, for example, doesn’t mean nRelate will show up.  You also need to check the SINGLE POSTS check box. This is done in case you only have one theme file, like INDEX.PHP, which renders on multiple pages.   By checking the appropriate box you can focus nRelate on the pages you want.
  3. Also under LAYOUT SETTINGS, make sure both “Automatic” layout settings (“Top of post” and “Bottom of post” ) are UNchecked. These are not needed since you are manually adding the nRelate code.
  4. Press SAVE CHANGES, and that’s it!

Comments are Closed.

Please post your questions on our Support Forum