Below, you’ll find a detailed guide on how to add the Read More Without Refresh 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 Read More Without Refresh Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the Read More Without Refresh Plugin and the shortcodes it provides:
"Read More Without Refresh is a convenient WordPress plugin that enhances user experience by allowing readers to expand content on your site without the need to refresh the page."
- [read_main]
Read More Without Refresh [read_main] Shortcode
The ‘Read More Without Refresh’ shortcode allows users to expand content on a webpage without reloading the page. Shortcode Name: Read More Without Refresh This shortcode uses JavaScript to toggle the visibility of the content. It generates a unique ID for each use, ensuring functionality even when used multiple times on the same page. The ‘more’ and ‘less’ attributes can be customized to change the text displayed on the toggle link. The default texts are ‘READ MORE’ and ‘READ LESS’.
Shortcode: [read_main]
Parameters
Here is a list of all possible read_main shortcode parameters and attributes:
more
– text displayed for the ‘read more’ linkless
– text displayed for the ‘read less’ link
Examples and Usage
Basic example – A simple use of the shortcode to implement the read more/less functionality. In this example, the default text for the read more and read less links will be used.
[read]
Advanced examples
Customizing the text for the read more and read less links. In this example, the ‘more’ attribute is set to ‘Show More’, and the ‘less’ attribute is set to ‘Show Less’. This will change the text displayed on the read more and read less links respectively.
[read more="Show More" less="Show Less"]
Using the shortcode within a post to hide part of the content. The content within the shortcode will be hidden until the read more link is clicked. The ‘more’ and ‘less’ attributes are used to customize the text of the links.
[read more="Continue Reading" less="Show Less"]This is the hidden content[/read]
PHP Function Code
In case you have difficulties debugging what causing issues with [read_main]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('read', 'read_main');
Shortcode PHP function:
function read_main($atts, $content = null) {
extract(shortcode_atts(array(
'more' => 'READ MORE',
'less' => 'READ LESS'
), $atts));
mt_srand((double)microtime() * 1000000);
$rnum = mt_rand();
$new_string = '<span><a onclick="read_toggle(' . $rnum . ', \'' . esc_html(get_option('rm_text')) . '\', \'' . esc_html(get_option('rl_text')) . '\'); return false;" class="read-link" id="readlink' . $rnum . '" style="readlink" href="#">' . esc_html(get_option('rm_text')) . '</a></span>' . "\n";
$new_string .= '<div class="read_div" id="read' . $rnum . '" style="display: none;">' . do_shortcode($content) . '</div>';
return $new_string;
}
Code file location:
read-more-without-refresh/read-more-without-refresh/readmoreoptions.php
Conclusion
Now that you’ve learned how to embed the Read More Without Refresh 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