Magento 1.9 – How to Remove Body Class from Specific Page

classcssmagento-1.9PHP

I'm using an extension that adds a class name vnecoms-cp to the body of adminhtml pages. This is then used to style the pages using css.

My problem is, this affects 1 specific page in a negative way. I would like a solution to remove the style from this specific page only. I believe the solution is to find a way to remove the vnecoms-cp class from the body tag of the page i want to remove the style from, so the style cannot be applied to that page at all.

here the code that is used to add the class to the body

<reference name="root">
        <action method="addBodyClass" ifconfig="vadmin/config/enabled"><className>vnecoms-cp</className></action>
    </reference>

enter image description here

as you can see it adds this to each pages body class.

i want to remove it from …/admin/inbox/index/…

Any help will be greatly appreciated!

Best Answer

If you're comfortable writing code and creating a new Module, follow these instructions to overwrite Mage_Adminhtml_Block_Page class. In your new custom class, add the following method:

/**
 * Remove CSS class from page body tag
 *
 * @param string $className
 * @return Mage_Adminhtml_Block_Page
 */
public function removeBodyClass($className)
{
    $className = preg_replace('#[^a-z0-9]+#', '-', strtolower($className));

    $existingClassNames = explode(' ', $this->getBodyClass());
    if ($i = array_search($className, $existingClassNames)) {
        unset($existingClassNames[$i]);
        $this->setBodyClass(implode(' ', $existingClassNames));
    }

    return $this;
}

From there, you can then add this to your Layout XML:

<reference name="root">
        <action method="removeBodyClass"><className>vnecoms-cp</className></action>
</reference>

Good luck!

Related Topic