Below, you’ll find a detailed guide on how to add the Read More & Accordion Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Read More & Accordion Plugin shortcodes not to show or not to work correctly.
Before starting, here is an overview of the Read More & Accordion Plugin and the shortcodes it provides:
"Read More & Accordion is a versatile WordPress plugin that allows you to add expandable 'Read More' sections and accordion-style content to your website with ease, enhancing user experience."
- [expander_maker]
- [yrm_accordion]
Read More & Accordion [expander_maker] Shortcode
The Expander Maker shortcode provides a customizable ‘read more’ functionality to WordPress posts. It allows users to set specific parameters like ‘more’ and ‘less’ text, and the ID. The shortcode processes the content, checks for existing ‘expander_maker’, and appends it if necessary. It then sets the attributes and fetches the saved options. If there are no saved options, it simply returns the content. If there are saved options, it determines the type of read more function to use, and creates an object of that type. It then sets the ‘more’ and ‘less’ names, and any other attributes specified. Finally, it creates a ReadMoreIncludeManager object, sets the ID, saved data, data object, and toggle content, and returns the rendered result. This provides a streamlined way to include expandable sections in your posts.
Shortcode: [expander_maker]
Parameters
Here is a list of all possible expander_maker shortcode parameters and attributes:
id
– unique identifier for the specific expander makermore
– text displayed for the “read more” linkless
– text displayed for the “read less” linkurl
– link for the “read more” button
Examples and Usage
Basic example – Show a default expandable content section using the ‘expander_maker’ shortcode.
[expander_maker id=1 /]
Advanced examples
Display an expandable content section with custom ‘more’ and ‘less’ labels.
[expander_maker id=1 more="Show More" less="Show Less" /]
Display an expandable content section with a custom URL.
[expander_maker id=1 url="https://example.com" /]
Display an expandable content section with custom ‘more’ and ‘less’ labels and a custom URL.
[expander_maker id=1 more="Read More" less="Read Less" url="https://example.com" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [expander_maker]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('expander_maker', array($this, 'doShortCode'));
Shortcode PHP function:
function doShortCode($args, $content) {
$id = 1;
if(strpos($content, 'expander_maker')) {
$content .= '[/expander_maker]';
}
$content = do_shortcode($content);
$this->setShortcodeArgs($args);
$this->setShortcodeContent($content);
$moreName = '';
$lessName = '';
if(isset($args['id'])) {
$id = $args['id'];
}
if(!empty($args['more'])) {
$moreName = $args['more'];
}
if(!empty($args['less'])) {
$lessName = $args['less'];
}
$dataObj = new ReadMoreData();
$dataObj->setId($id);
$this->setId($id);
$savedData = $dataObj->getSavedOptions();
$this->setSavedData($savedData);
if(empty($savedData)) {
return $content;
}
$type = $savedData['type'];
$className = ucfirst($type).'TypeReadMore';
$classPaths = YRM_CLASSES;
global $YRM_TYPES;
global $YRM_EXTENSIONS;
if(!empty($YRM_TYPES[$type])) {
$classPaths = $YRM_TYPES[$type];
}
$extensionsInfo = YrmConfig::extensions();
$typeObj = $this->getTypeObjFromClass($classPaths, $className);
if(in_array($type, $YRM_EXTENSIONS) && !empty($extensionsInfo[$type]) && empty($extensionsInfo[$type]['useMainOptions'])) {
return $this->renderExtensionContent($typeObj);
}
$savedData['attrMoreName'] = $moreName;
$savedData['attrLessName'] = $lessName;
foreach($args as $name => $value) {
if (!empty($value)) {
$savedData[$name] = $value;
}
}
if(!empty($args['url'])) {
$savedData['shortcodeURL'] = $args['url'];
}
$includeManagerObj = new ReadMoreIncludeManager();
$includeManagerObj->setId($id);
$includeManagerObj->setData($savedData);
$includeManagerObj->setDataObj($dataObj);
$includeManagerObj->setToggleContent($content);
return $includeManagerObj->render();
}
Code file location:
expand-maker/expand-maker/classes/ReadMoreShortCode.php
Read More & Accordion [yrm_accordion] Shortcode
The YRM Accordion shortcode is a powerful tool in WordPress. It allows the creation of expandable content sections, enhancing user experience. This shortcode generates an accordion-style read more section. The ‘id’ attribute can be customized to identify different accordions. It utilizes the AccordionTypeReadMore class to render the content.
Shortcode: [yrm_accordion]
Parameters
Here is a list of all possible yrm_accordion shortcode parameters and attributes:
id
– Represents the specific accordion element to display.
Examples and Usage
Basic example – Utilizes the shortcode to display an accordion by referencing its ID.
[yrm_accordion id=1 /]
Advanced examples
Here, we use the shortcode to display an accordion by referencing its ID. If the specified ID is not found, the default accordion with ID 1 will be displayed.
[yrm_accordion id=2 /]
Another advanced usage could be to display multiple accordions by providing their IDs. Here, we are referencing three accordions with IDs 1, 2, and 3.
[yrm_accordion id=1 /]
[yrm_accordion id=2 /]
[yrm_accordion id=3 /]
Please note that in the current implementation of the ‘yrm_accordion’ shortcode, the ‘id’ is the only parameter that can be passed. For more advanced usage, the PHP code of the shortcode would need to be extended to accept and process more parameters.
PHP Function Code
In case you have difficulties debugging what causing issues with [yrm_accordion]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('yrm_accordion', array($this, 'accordionShortcode'));
Shortcode PHP function:
function accordionShortcode($args, $content) {
$id = 1;
if (!empty($args['id'])) {
$id = $args['id'];
}
require_once(YRM_CLASSES.'AccordionTypeReadMore.php');
$accordion = new AccordionTypeReadMore();
$accordion->setId($id);
return $accordion->renderContent();
}
Code file location:
expand-maker/expand-maker/classes/ReadMoreShortCode.php
Conclusion
Now that you’ve learned how to embed the Read More & Accordion Plugin shortcodes, 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