EVENT-AFTERRENDER-001

onAfterRender() { $body = JResponse::getBody(); }

onAfterRender HTML string hacks

JResponse body swapping is Joomla 3. Joomla 4+ will surprise you with compressed output and split assets.

onAfterRender() { $body = JResponse::getBody(); }Document events / WebAssetManager

Dies at Joomla 3 → 4J3: Works nativelyJ4: Changed behaviourJ6: Changed behaviourBC plugin: no — already dead on J4Architecture change — no auto-fixEvents / plugins

What you will see

  • Class "JResponse" not found

Symptoms people search

script inject plugin broken · onAfterRender · JResponse

Replace this code

Swap onAfterRender() { $body = JResponse::getBody(); } for Document events / WebAssetManager.

Joomla 3

Remove or stop calling this

public function onAfterRender() {
    $body = JResponse::getBody();
    $body = str_replace('</body>', $js . '</body>', $body);
    JResponse::setBody($body);
}

Joomla 4 / 6

Use this instead

Add scripts with WAM. If you must mutate HTML, use the document after render APIs — JResponse is gone.

How to fix it

  1. 1Prefer WebAssetManager.
  2. 2If you still str_replace HTML, test with gzip on.

Also known as

JResponse · onAfterRender · setBody · getBody

There is no 1:1 swap for this one. The architecture changed. If you cannot rewrite it, Infyways can.

Related issues

Get in touch

Have a project in mind? Let's talk about it.

Tell us what you're building. Whether it's a new site, an online store, a mobile app, or something that needs AI under the hood, we'll get back to you within a business day.

Free consultation
No commitment, no pressure
Reply within 24 hours
Usually much faster

Prefer a direct conversation?

Request a project quote

Tell us about your project

Fill out the quick form and we'll reach out.