Custom Related Posts Shortcode

Below, you’ll find a detailed guide on how to add the Custom Related Posts Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Custom Related Posts Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Custom Related Posts Plugin and the shortcodes it provides:

Plugin Icon
Custom Related Posts

"Custom Related Posts is a dynamic WordPress plugin designed to enhance audience engagement. It easily allows you to add relevant content links, boosting SEO and user experience."

★★★★☆ (43) Active Installs: 3000+ Tested with: 6.3.2 PHP Version: false
Included Shortcodes:
  • [custom-related-posts]

Custom Related Posts [custom-related-posts] Shortcode

The Custom-Related-Posts shortcode is a handy tool for displaying related posts on your WordPress site. It uses the post ID and options specified to output a list of related posts. This shortcode fetches related posts based on the current post’s ID. The options parameter allows customization, offering flexibility in the display of these related posts.

Shortcode: [custom-related-posts]

Examples and Usage

Basic example – A simple usage of the shortcode to display related posts for the current post.

[custom-related-posts]

Advanced examples

Using the shortcode to display related posts for a specific post by referencing the post ID. This can be useful if you want to manually specify the post to display related content for.

[custom-related-posts id="123"]

Using the shortcode to display related posts for the current post, but limit the number of related posts displayed. This can be useful if you want to control the amount of related content shown.

[custom-related-posts limit="5"]

Using the shortcode to display related posts for a specific post and limit the number of related posts displayed. This combines the functionality of the previous two examples.

[custom-related-posts id="123" limit="5"]

Using the shortcode to display related posts for the current post, but exclude certain posts by referencing their IDs. This can be useful if there are specific posts you do not want to be shown as related content.

[custom-related-posts exclude_ids="123,456"]

Using the shortcode to display related posts for a specific post, limit the number of related posts displayed, and exclude certain posts. This combines all of the functionality of the previous examples.

[custom-related-posts id="789" limit="5" exclude_ids="123,456"]

PHP Function Code

In case you have difficulties debugging what causing issues with [custom-related-posts] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'custom-related-posts', array( $this, 'shortcode' ) );

Shortcode PHP function:

                    function shortcode( $options )
    {
        return CustomRelatedPosts::get()->helper( 'output' )->output_list( get_the_ID(), $options );
    }
                    

Code file location:

custom-related-posts/custom-related-posts/helpers/shortcode.php

Conclusion

Now that you’ve learned how to embed the Custom Related Posts Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *