Below, you’ll find a detailed guide on how to add the Inline 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 Inline Related Posts Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the Inline Related Posts Plugin and the shortcodes it provides:
"Inline Related Posts is a powerful WordPress plugin that automatically inserts related posts within your content, boosting engagement and reducing bounce rate."
- [irp]
Inline Related Posts [irp] Shortcode
The Intelly Related Posts (IRP) shortcode integrates related posts into your content. It checks if the IRP Pro plugin is active and if the options are enabled. It accepts various parameters like ‘posts’, ‘cats’, ‘tags’, ‘count’, etc., permitting customization. If no specific posts, categories, or tags are defined, it dynamically fetches related posts. The shortcode also handles the visual aspects, like colors and shadows, and includes CSS for styling. If the shortcode successfully generates a related posts box, it sets the ‘shortcode used’ option to true.
Shortcode: [irp]
Parameters
Here is a list of all possible irp shortcode parameters and attributes:
posts
– Defines specific posts to display.cats
– Specifies categories to pull posts from.tags
– Specifies tags to pull posts from.count
– Sets the number of posts to display.theme
– Sets the visual theme for the posts.demo
– If set to TRUE, displays a demo of the related posts.ctaText
– Specifies the text for the call-to-action button.ctaTextColor
– Sets the color of the call-to-action text.postTitleColor
– Sets the color of the post title text.boxColor
– Defines the color of the post box.borderColor
– Defines the color of the post box border.hasPoweredBy
– If set to TRUE, displays ‘Powered by’ text.hasShadow
– If set to TRUE, adds a shadow effect to the box.defaultsColors
– If set to TRUE, uses default colors.includeCss
– If set to TRUE, includes CSS in the box.
Examples and Usage
Basic example – A shortcode to display one related post with default settings.
[irp count=1 /]
Advanced examples
Using the shortcode to display three related posts, with a specific theme, and custom ‘Call to Action’ text color.
[irp count=3 theme="mytheme" ctaTextColor="#ff0000" /]
Displaying related posts from specific categories and tags, with a custom box color and border color.
[irp cats="cat1,cat2" tags="tag1,tag2" boxColor="#000000" borderColor="#ffffff" /]
Using the shortcode to display related posts with a custom ‘Call to Action’ text, post title color, and without the ‘Powered By’ text.
[irp ctaText="Read More" postTitleColor="#123456" hasPoweredBy="false" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [irp]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('irp', 'irp_shortcode');
Shortcode PHP function:
function irp_shortcode($atts, $content='') {
global $irp, $post;
if($irp->Plugin->isActive(IRP_PLUGINS_INTELLY_RELATED_POSTS_PRO)) {
return $content;
}
if(!$irp->Options->isActive()) {
return '';
}
$default=array(
'posts'=>''
, 'cats'=>''
, 'tags'=>''
, 'count'=>1
, 'theme'=>''
, 'demo'=>FALSE
, 'ctaText'=>'default'
, 'ctaTextColor'=>'default'
, 'postTitleColor'=>'default'
, 'boxColor'=>'default'
, 'borderColor'=>'default'
, 'hasPoweredBy'=>'default'
, 'hasShadow'=>'default'
, 'defaultsColors'=>FALSE
, 'includeCss'=>TRUE
);
$options=$irp->Utils->shortcodeAtts($default, $atts);
if(isset($options['postId'])) {
unset($options['postId']);
}
$options['demo']=$irp->Utils->isTrue($options['demo']);
$options['count']=intval($options['count']);
if($options['count']<=0) {
return '';
}
if($options['posts']=='' && $options['cats']=='' && $options['tags']=='') {
//dynamic
$ids=$irp->Options->getToShowPostsIds($options['count'], TRUE);
} else {
if($options['posts']=='current' && $post && isset($post->ID)) {
$options['posts']=$post->ID;
}
//static
$ids=$irp->Manager->getRelatedPostsIds($options);
}
$keys=array('ctaText', 'ctaTextColor', 'postTitleColor', 'boxColor', 'borderColor', 'hasPoweredBy', 'hasShadow');
foreach($keys as $k) {
if($options[$k]=='default') {
unset($options[$k]);
}
}
$options['includeCss'] = ! $irp->Options->isDoNotIncludeCssInBox();
$result=irp_ui_get_box($ids, $options);
if($result!='') {
$irp->Options->setShortcodeUsed(TRUE);
}
return $result;
}
Code file location:
intelly-related-posts/intelly-related-posts/includes/core.php
Conclusion
Now that you’ve learned how to embed the Inline 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.
Leave a Reply