versvs
versvs

Reputation: 643

How to remove CSS and JS from a certain content-type in Drupal 7

I've come here after looking for how to selectively add a CSS or JS to a given node based on its view mode and content type. That question is answered pretty straightforward here (http://stackoverflow.com/questions/8295498/how-to-add-css-and-js-files-on-node-pages-independent-of-the-theme).

Now I'd love to clear everything: I'm looking for a way to show my desired CSS and JS but only that, with no other JS and CSS. I'm trying to integrate Impress.js (And I don't like the available solutions) and it seems to be conflicting with Jquery, as both scripts are properly loaded but both latest Firefox and Chromium browsers throw the "old browser" message.

Any ideas on how to unset every single CSS and JS so that the CSS and JS I want to use are the only ones really active?

Thanks!

I've tried the following, to no success:

$mycss = $vars['styles'];

unset($micss[drupal_get_path('module','system') .'/system.base.css']);

...

unset($micss[drupal_get_path('module','toolbar') .'/toolbar.css']);

$vars['styles'] = $mycss;

(I added a lot of different css i want to get rid of, but this explains the idea). It didn't work, though :)

Edit. I'm sorry for the bad markup, I'm looking for a way to clean/mark code.

Upvotes: 1

Views: 5560

Answers (1)

jonshot
jonshot

Reputation: 805

In your custom module use:

function yourmodule_js_alter(&$js) {
    unset(
        $js['misc/drupal.js'],
        $js['misc/jquery.js']
        .... etc.
    );
}

You say you want to only do this for certain content types, so try:

if(arg(0) == 'node') {
    $node = node_load(arg(1));
    if($node->type == 'your_content_type') {
        unset(
            $js['misc/drupal.js'],
            $js['misc/jquery.js']
            .... etc.
        );
    }
}

Jonny

Upvotes: 2

Related Questions