0

I am developing a plugin to get rid of any rel="nofollow" on HTML links using a buffer, but its not working. I am testing it with a nofollow link on a Custom HTML Module.

I thought that "JFactory::getApplication()->getBody();" would output me the body content but was I wrong?

The aim is to remove any nofollow on template, modules and component.

Here my code so far:

function onContentAfterDisplay()
{
$buffer = JFactory::getApplication()->getBody();
$buffer = str_ireplace(' rel=”nofollow”', '', $buffer);
$buffer = str_ireplace(' rel=\'nofollow\'', '', $buffer);
JFactory::getApplication()->setBody($buffer);
}
1

onContentAfterDisplay isn't called at a point when the full getBody() content has been generated. It is rather called at the points where components and modules are generating their individual views.

As such, JFactory::getApplication()->getBody() content will not exist at the time you are calling it.

Try the following to see which content it is selecting - most likely it will just be your main component area, as not all components and modules will trigger it:

public function onContentAfterDisplay($context, &$row, &$params, $page = 0)     {

   $row->text="hello";

}

If you need to call a plugin that grabs all the page's html, then onAfterRender is probably going to be the one.

public function onAfterRender()
{
    // Do something onAfterRender

    $buffer = JFactory::getApplication()->getBody();
    JFactory::getApplication()->setBody($buffer."hello world");
}

(Note that here you'd need to view the source to see the hello world as it will be outside the html area)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.