Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable assets if block isn't in page #38

Closed
ipatate opened this issue Oct 5, 2021 · 2 comments
Closed

Disable assets if block isn't in page #38

ipatate opened this issue Oct 5, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@ipatate
Copy link

ipatate commented Oct 5, 2021

The assets is in all pages. For the moment i use this snippet for remove assets if the block isn't in page.

/**
 * Completely remove assets from plugin block leaflet if isn't in page
 */
function disableLeafletAsset()
{
  $id = get_the_ID();
  if (!has_block('map-block-leaflet/map-block-leaflet', $id)) {
    wp_dequeue_script('lib-js-map-block-leaflet');
    wp_dequeue_script('lib-js-map-block-leaflet-cluster');
    wp_dequeue_script('js-editor-map-block-leaflet');

    wp_dequeue_style('css-editor-map-block-leaflet');
    wp_dequeue_style('lib-css-map-block-leaflet');
    wp_dequeue_style('lib-css-map-block-leaflet-cluster');
  }
}


add_action('wp_enqueue_scripts', 'disableLeafletAsset');
@goiblas
Copy link
Owner

goiblas commented Oct 5, 2021

Thanks for your contribution, in the past I had problems trying to exclude those assets. I will try your solution.

@goiblas goiblas assigned goiblas and unassigned goiblas Oct 5, 2021
@goiblas goiblas added the enhancement New feature or request label Oct 5, 2021
@goiblas goiblas closed this as completed Nov 27, 2021
@goiblas
Copy link
Owner

goiblas commented Nov 27, 2021

Added in version 2.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants