Remove front-end JS files?

Viewing 6 posts - 1 through 6 (of 6 total)
#163449

Freedom
Participant

Hi,

I hope to use WP Download Manager just for protecting links that I upload in the backend via WP-Admin.

Unfortunately, WPDM adds its own CSS and JS on every page of my site. I have turned off what I can via the Settings page (and thank you for at least having that), but I don’t see the point of loading the JS on every single page of my site, especially when my links are behind a login gate anyway.

Is there any way to remove the JS either altogether (I only want to display the links – actually right now it even forces a filetype con and I’d like to remove that but haven’t found the setting for it), or restrict it to only pages that there are links? Or only for logged in members at least?

Thanks.

P.S. Maybe you guys have already posted the solution for it – I found this topic in Google but it’s in the Pro forum and I can’t access its contents: https://www.wpdownloadmanager.com/support/topic/remove-css-and-js-files/

#163452

Tanvir
Moderator

Hello,
Hope you are well.
You can remove js loading from download-manager/download-manager.php file
In example if you want to disable front.js loading, just delete this line wp_register_script('wpdm-frontjs', plugins_url('/download-manager/assets/js/front.js'), array('jquery'), WPDM_VERSION);
In this way you can unload other js files too.
However please always keep backup if you do these changes as sometimes it may affect on your frontend. Also if you update or reinstall the plugin, all codes will be restored.
Thanks

#163454

Freedom
Participant

Thank you for the quick response.

Is there any way to do this with a hook/filter? I’d prefer if I didn’t have to edit core files every time I do updates as it’s not best practice.

If not, is it possible to put a hook/filter on the roadmap? Even better if it could work in the Settings screen you already have setup for this purpose, but anything persistent would be really nice.

#163459

Tanvir
Moderator

Hello @freedom,

You can add action to your active theme functions.php file like this:

function wpdm_dequeue_unnecessary_scripts() {
    wp_dequeue_script( 'wpdm-frontjs' );
}
add_action( 'wp_print_scripts', 'wpdm_dequeue_unnecessary_scripts' );

You can remove front.js by calling handle wpdm-frontjs inside this function like this.

Thanks

#163816

Freedom
Participant

Great solution, thank you! It removes it on all pages where WPDM is not used, but keeps it on pages which show WPDM shortcodes. ๐Ÿ™‚

I noticed these two things are also included on ALL pages on my site:

<meta name="generator" content="WordPress Download Manager 3.2.18" />
<style>
        /* WPDM Link Template Styles */        </style>

Even if I remove all other generator tags with this:

remove_action( 'wp_head', 'wp_generator' );

The meta generator still displays.

Is there any way to remove them both – either at all or when not in use?

  • This reply was modified 2 years, 6 months ago by Freedom.
#163848

Tanvir
Moderator

Hello,

You have to remove/comment this line:
add_action('wp_head', array($this, 'addGenerator'), 9999);
from download-manager/src/__/apply.php file
and sorry there is no way to remove from function.php

Thanks

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘Remove front-end JS files?’ is closed to new replies.