1

I am very new to Craft and how it works. I've got a client with a Craft site (v2.9.2), that I help them with. It was created by another developer.

I want to help them tidy up their Assets.

There are two folders (on S3) for their Assets. /Media and /Media/Files.

Scanning by eye, I can see /Media/Files appears to be a subset of what's in Media (meaning, they are duplicate files). Before we potentially delete the /Media/Files folder, I'd like to programatically confirm if any of them are being used. My suspicion is only files in /Media/ are used on the site.

Is there any easy way to see which assets are in use, and where they are used?

I found questions on StackExchange re how to see what media is not in use, such as this one. I also found a question on how to do something similar to what I need.

Although, to be honest, I had no idea where I'd utilise such code. I'm not going to get into creating a new plug-in.

For example, this was shared in the answer to that question:

{% set content = craft.entries.section('content').find() %}
{% set usedFotos = craft.assets.relatedTo(content).order('filename').find() %}

{# Loop throught the array of assets #}
{% for usedFoto in usedFotos %}

    <h2>{{ usedFoto.filename }}</h2>
    <ul>

        {# Loop throught entries related to this asset #}
        {% for entry in craft.entries.relatedTo(usedFoto).order('title') %}
            <li>{{ entry.title }}</li>
        {% endfor %}

    </ul>

{% endfor %}

Where would I utilise this code?

1

There's a plugin that you can use to find unused assets: Asset Usage

This gives you an extra column in the Assets listing to indicate if an asset is used or not. Unfortunately, the Craft 2 version doesn't have the console command to delete all unused assets that the Craft 3 version does, but this may help you anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.