Skip to content

Universal enqueue function to load JS/CSS assets in site frontend/admin/login pages #13

@eliot-akira

Description

@eliot-akira

Tangible Blocks and L&L, which have dynamic frontend features that require JS & CSS, like a gallery or slider. I have a feeling some are only enqueued on the site frontend but not on admin side. And definitely not in the login page.

For blocks and templates to support all contexts, it will be good to create a "universal enqueue" function for all those dynamic features to use.

Similar to:

How the Fields module enqueues the WP media uploader.

  if (is_admin()) {

    // Admin

    // Before document head
    $action = 'admin_enqueue_scripts';

    if (doing_action($action) || did_action($action)) {
      $action = 'admin_footer'; // During and after
    }

  } elseif (is_login()) {

    // Login

    // Before document head
    $action = 'login_enqueue_scripts';

    if (doing_action($action) || did_action($action)) {
      $action = 'login_footer'; // During and after
    }
  } else {

    // Site frontend

    // Before document head
    $action = 'wp_enqueue_scripts';

    if (doing_action($action) || did_action($action)) {
      $action = 'wp_footer'; // During and after
    }
  }

https://github.com/TangibleInc/fields/blob/495d4458b62d5fdcb0b7bd006d42ee436caa3820/fields/media.php#L11-L47

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions