> For the complete documentation index, see [llms.txt](https://whoisandywhite.gitbook.io/porterwp/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://whoisandywhite.gitbook.io/porterwp/features/assets.md). Agents can also search and read this documentation through its [MCP server](https://whoisandywhite.gitbook.io/porterwp/~gitbook/mcp).

# Assets

PorterWP registers theme-owned public and editor assets from [`porter.json`](https://whoisandywhite.gitbook.io/porterwp/getting-started/configuration-files/porter-json.md). Each object key becomes the WordPress handle.

## Configuration

```jsonc
{
  "settings": {
    "public": {
      "styles": {
        "theme-app": {
          "src": "./assets/dist/css/app.min.css",
          "deps": [],
          "ver": "1.2.0"
        }
      },
      "scripts": {
        "theme-app": {
          "src": "./assets/dist/js/app.js",
          "deps": ["wp-i18n"],
          "args": {
            "in_footer": true,
            "strategy": "defer"
          },
          "data": {
            "crossorigin": "anonymous"
          }
        }
      }
    },
    "admin": {
      "editor_styles": {
        "theme-editor": "./assets/dist/css/editor.min.css"
      },
      "editor_scripts": {
        "theme-editor": "./assets/dist/js/editor.js"
      }
    }
  }
}
```

The actual file must be strict JSON. A string is accepted as shorthand for an object containing only `src`.

## Resolution and defaults

* A `src` beginning `./` is resolved from the active theme URI.
* Other source values are passed to WordPress as supplied.
* `ver` defaults to the active theme version.
* Public style and script dependencies default to `[]`.
* Editor styles default to `wp-edit-blocks`.
* Editor scripts default to `wp-blocks`, `wp-i18n`, `wp-element`, `wp-components` and `wp-editor`.
* Script `args` defaults to `{ "in_footer": true }` and supports WordPress loading strategies such as `defer` and `async`.

Every configured asset must resolve to a non-empty `src`.

## Script attributes

Public script entries may contain `data`. PorterWP adds those trusted theme-configured key/value pairs to the matching script tag. A boolean `true` produces a valueless attribute; other values produce `attribute="value"`.

Prefer WordPress's `args.strategy` for standard `defer` or `async` behaviour. Reserve `data` for attributes WordPress's enqueue API does not represent.

## Runtime contexts

| Collection                      | Hook                                     | Context                  |
| ------------------------------- | ---------------------------------------- | ------------------------ |
| `settings.public.styles`        | `wp_enqueue_scripts`                     | Frontend                 |
| `settings.public.scripts`       | `wp_enqueue_scripts`                     | Frontend                 |
| `settings.admin.editor_scripts` | `enqueue_block_editor_assets`            | Block editor             |
| `settings.admin.editor_styles`  | `enqueue_block_assets` plus `is_admin()` | Editor-side block assets |

PorterWP-owned scripts and styles use `PORTER_VERSION`; theme-owned assets use their configured version or the active theme version.

## Default-argument filters

Four filters receive the defaults array before it is merged into each configured asset:

* [`porter_public_styles_default_args`](https://whoisandywhite.gitbook.io/porterwp/developer-api/hooks/porter_public_styles_default_args.md)
* [`porter_public_scripts_default_args`](https://whoisandywhite.gitbook.io/porterwp/developer-api/hooks/porter_public_scripts_default_args.md)
* [`porter_editor_styles_default_args`](https://whoisandywhite.gitbook.io/porterwp/developer-api/hooks/porter_editor_styles_default_args.md)
* [`porter_editor_scripts_default_args`](https://whoisandywhite.gitbook.io/porterwp/developer-api/hooks/porter_editor_scripts_default_args.md)

For example, add a shared public style dependency without repeating it in JSON:

```php
add_filter( 'porter_public_styles_default_args', function ( array $defaults ): array {
    $defaults['deps'][] = 'wp-block-library';
    $defaults['deps'] = array_values( array_unique( $defaults['deps'] ) );
    return $defaults;
} );
```

Per-asset JSON values take precedence over these defaults. Return the complete defaults array from each filter.
