Skip to content

Conversation

@davidwebca
Copy link

@davidwebca davidwebca commented Mar 18, 2020

Hi! Me again years later. I started giving up on using sprites nowadays to use simple svg includes so I needed a way to pull icon files from a folder. Some other plugins say they're doing this, but I had compatibility issues and by reading the code of your plugin again, I realized we could simple filter the media files to add our own. Here's how I'm using it right now, but feel free to tell me how to rework this and I'll adapt the pull request.

add_filter( 'acf_svg_icon_wp_media_svgs', function ( $svg ) {
    $files = glob(get_stylesheet_directory() . '/dist/icons/*.svg');
    foreach ($files as $key => $file) {
        $svg[] = [
            'type'     => 'media',
            'id'       => basename($file),
            'file'     => $file,
            'file_url' => get_stylesheet_directory_uri() . '/dist/icons/' . basename($file),
        ];
    }
    return $svg;
});

davidwebca and others added 4 commits March 18, 2020 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant