开发者 |
McGuive7
MIGHTYminnow Braad |
---|---|
更新时间 | 2021年6月21日 23:25 |
捐献地址: | 去捐款 |
PHP版本: | 3.5 及以上 |
WordPress版本: | 5.7.2 |
版权: | GPLv2 or later |
版权网址: | 版权信息 |
[tax_icon term_id="" class=""]
2. PHP Function
<?php tax_icons_output_term_icon( $term_id, $class ); ?>
Both methods of output utilize the same attributes/parameters:
term_id
The ID of the taxonomy term for which to output the associated icon. If no term_id is specified, the plugin will attempt to determine the current taxonomy term.
class
Any extra classes you would like appened to the output HTML icon element.
Example
Assuming we have a "Travel" category with an term ID of 1 which has been assigned the "Plane" icon, both of the following methods will output the same thing:
Shortcode/PHP:
[tax_icon term_id="1" class="extra-class"]
<?php tax_icons_output_term_icon( 1, 'extra-class' ); ?>
Output:
<i class="fa fa-plane extra-class"></i>
Adding Custom Icons
To add your own icons to the Taxonomy Icons dropdown selector, you'll need to 1) Add your icons to the list with the tax_icons_icon_array
filter, and 2) Enqueue you custom icon font CSS.
1. Add your icons to the list
Use the tax_icons_icon_array
filter to add your custom icons as follows:
`
add_filter( 'tax_icons_icon_array', 'prefix_add_tax_icons' );
function prefix_add_tax_icons( $icons ) {
$icons = array(
'Icon One' => 'icon-one-class',
'Icon Two' => 'icon-two-class',
);
return $icons;
}
`
Just make sure you return an array with the icon names as keys, and the icon CSS classes as values.
2. Enqueue your custom icon font CSS
Use the wp_enqueue_scripts
and admin_enqueue_scripts
hooks to enqueue your custom icon font stylesheet in both the front-end and back-end. This is necessary for the icons to render on both the public and admin sides of your site.
/taxonomy-icons
directory to the /wp-content/plugins/
directory.