How to add jquery readmore function (expand/collapse) to magento CMS pages

How to add jquery readmore function (expand/collapse) to magento CMS pages

July 18, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to add jquery readmore function (expand/collapse) to magento CMS pages

Adding jQuery Read More Functionality to Magento CMS Pages

Are you looking to add a read more/collapse functionality to your Magento CMS pages? You’re not alone! Long blocks of text can be overwhelming for users. By implementing a “read more” link, you can improve the user experience by allowing visitors to expand or collapse content.

Understanding Your Requirements

Based on your description, here’s what you need:

  • A “Read More” button that collapses long CMS texts.
  • The ability to place this “Read More” link after a specific paragraph or character limit (e.g., 250 characters).
  • Ideally, you’d like to add the “read more” shortcode [readmore] in the Magento backend.

Step-by-Step Implementation

1. Enable jQuery

First, ensure that jQuery is enabled on your Magento store. By default, it should be included in the footer via the jquery.js file located at skin/frontend/base/default/js/jquery.js.

If it’s not already loaded, you can add it manually to your theme’s layout XML files using the following code:

<reference name="head">
    <action method="addItem">
        <type>js</type>
        <name>jquery.js</name>
        <params/>
    </action>
</reference>

2. Include Read More Script

Next, you’ll need to include the read more script in your theme. You can use a simple jQuery plugin like ReadMore.js for this purpose.

Add the script file (e.g., read-more.min.js) to your theme’s JavaScript folder, and then link it in your layout XML:

<reference name="head">
    <action method="addItem">
        <type>js</type>
        <name>read-more.js</name>
        <params/>
    </action>
</reference>

Replace read-more.js with the actual filename you’re using.

3. Add Read More Shortcode

Now, let’s implement the [readmore] shortcode feature in your CMS pages. You can create a new module to handle this functionality.

In your module’s config.xml file, define an event observer for core_block_abstract_to_html_before:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
    <event name="core_block_abstract_to_html_before">
        <observer name="readmore_shortcode_handler" instance="Vendor\ReadMore\Observer\CmsShortcodeHandler"/>
    </event>
</config>

Next, create a CmsShortcodeHandler class in your module to handle the [readmore] shortcode:

public function execute(\Magento\Framework\Event\Observer $observer)
{
    $block = $observer->getBlock();
    $html = $block->getText();

    if (strpos($html, '[readmore]') !== false) {
        // Implement your read more logic here using ReadMore.js
        // ...
    }

    return $this;
}

4. Update Your CMS Pages

Finally, update your CMS pages to include the [readmore] shortcode where you want the “Read More” link to appear.

Conclusion

By following these steps, you should be able to add a jQuery read more/collapse functionality to your Magento CMS pages using a simple plugin and custom shortcode handling. This will significantly improve the readability of long content for your users.

Remember to clear your cache after making changes in the Magento backend.

If you need further assistance or want to explore advanced features like dynamic content loading, be sure to check out Laravel Company’s blog for more Magento development insights.

Database Extensions Themes Admin

Our network