-
Search for "Support For Icomoon with Advanced Custom Fields" from your CMS Admin > Plugins page, or download the zip file from WordPress Plugin Repository or releases.
-
Upload the plugin to your
wp-content/pluginsdirectory. -
Activate the plugin in the CMS admin plugins list.
-
Go to Field Groups > Create new Field and choose "Icomoon" Type in Content Group.
- Create a Field Group: In the WordPress admin, navigate to Custom Fields > Field Groups and create a new field group.
- Add IcoMoon Field: Add a new field and select "Icomoon" as the field type.
- Configure Field Settings:
- Selection.json: Input the path of
selection.jsonfile from IcoMoon and ensure this file is uploaded to your theme or plugin directory. Leave empty to use the plugin's selection.json. - Return value: Choose the desired return format (
Icon element,Icon class,SVG elementorArray).
- Selection.json: Input the path of
- Assign the field group to the desired post type or page.
To display the selected IcoMoon icon on the frontend, you need to enqueue the IcoMoon font files and styles in your theme. Below is an example of how to properly enqueue the IcoMoon assets and output the selected icon.
Add the following code to your theme's functions.php file to enqueue the IcoMoon stylesheet and font files.
// Enqueue IcoMoon assets (should be in functions.php)
add_action( 'wp_enqueue_scripts', 'vii_acf_icomoon_enqueue_styles' );
function vii_acf_icomoon_enqueue_styles() {
wp_enqueue_style( 'vii-icomoon', get_template_directory_uri() . '/assets/css/style.css', array(), '1.0.0' );
}Notes:
- Replace
/assets/css/style.csswith the actual path to your IcoMoonstyle.cssfile. - Ensure the font files referenced in
style.cssare correctly placed in the specified directory (e.g.,/assets/fonts/). - The IcoMoon
style.csstypically includes the@font-facerule to load the font files.
Use the ACF get_field() function to retrieve the selected icon and display it in your template. The output depends on
the return format configured in the field settings.
Example 1: Return value Set to Icon class
If the return value is set to Icon class, the field returns the icon's CSS class (e.g., icon-home).
<?php
$icon_class = get_field( 'icon' ); // Field name: 'icon'
if ( $icon_class ) {
echo '<i class="' . esc_attr( $icon_class ) . '"></i>';
}
?>Example 2: Return value Set to Icon element/SVG element
If the return value is set to Icon element or SVG element, the field returns the full icon HTML (e.g.,
<i class="icon-home"></i> for Icon element and the full SVG code for SVG element).
<?php
$icon_html = get_field( 'icon' );
if ( $icon_html ) {
echo esc_html($icon_html);
}
?>Example 3: Return value Set to Array
If the return value is set to Array, the field returns an array containing the full data of an icon.
<?php
$icon = get_field( 'icon' );
if ( $icon && is_array( $icon ) ) {
var_dump($icon); // dump the icon array for debugging, you can use it to get the icon name, class, and SVG code
}
?>Notes:
- Always use
esc_attr()oresc_html()to sanitize output for security. - Ensure the IcoMoon font family name (e.g.,
icomoon) matches the one defined in yourstyle.css. - The
<i>tag is commonly used for IcoMoon icons, but you can use any HTML element as long as the correct CSS class or font-family is applied.
Here’s an example of how you might integrate the IcoMoon icon in a WordPress template (e.g., single.php):
<?php
// Enqueue IcoMoon assets (should be in functions.php)
add_action( 'wp_enqueue_scripts', 'vii_acf_icomoon_enqueue_styles' );
function vii_acf_icomoon_enqueue_styles() {
// use your icomoon style
wp_enqueue_style( 'vii-icomoon', get_template_directory_uri() . '/assets/css/style.css', array(), '1.0.0' );
// or you can use the plugin's icomoon style
wp_enqueue_style( 'vii-icomoon', ACFICOMOON_STYLESHEET_DIR . '/assets/css/icomoon.css', array(), '1.0.0' );
}
// In your template file
$icon_class = get_field( 'icon' );
if ( $icon_class ) {
?>
<div class="icon-container">
<i class="<?php echo esc_attr( $icon_class ); ?>"></i>
</div>
<?php
}
?>- Icons Not Displaying: Ensure the
selection.jsonfile path is correct, font files are accessible, and thestyle.cssis properly enqueued. - 404 Errors for Font Files: Verify the font file paths in
style.cssmatch their actual location in your theme directory. - Incorrect Font Family: Check that the font-family name in your CSS matches the one defined in IcoMoon’s
style.css.
- ACF: Compatible with ACF 5.7+.
- WordPress: Tested up to WordPress 6.6.2.
- PHP: Requires PHP 7.2 or higher.
A complete listing of all notable changes to Support For Icomoon with Advanced Custom Fields is documented in CHANGELOG.md.
Contributions are welcome! Please submit a Pull Request or open an issue on GitHub.


