如何在自定义帖子类型UI菜单图标区域中添加字体真棒图标?

时间:2017-07-08 02:46:02

标签: wordpress

我想在自定义帖子类型UI菜单图标区域添加字体真棒图标,但我无法添加。伙计们,我怎么能做任何想法?谢谢。

enter image description here

enter image description here

4 个答案:

答案 0 :(得分:1)

如果你可以将这些文件粘贴到functions.php和style.css中,并且知道查看wordpress提供的body类的自定义post类型类

要为WordPress自定义帖子类型使用Font Awesome,您需要编写一些CSS:只需定位一个CPT菜单项(检查WordPress管理侧栏以找到正确的CSS ID),如下所示:

#adminmenu #menu-posts-custom_post_type_name .wp-menu-image:before {
 content: "\f135"; //find this by clicking on the individual icon on Font 
 Awesome's site.
font-family: 'FontAwesome' !important;
 font-size: 18px !important;
}

接下来,使用admin_head hook将这些样式添加到WordPress管理员:

function namespaced_admin_styles_function() {

  echo '<link href="/link/to/admin-styles.css"  rel="stylesheet">';
}

add_action('admin_head', 'namespaced_admin_styles_function');

......你已经开始跑了!嗯,不太好。您仍然需要将Font Awesome样式表添加到WordPress管理员和站点的前端。幸运的是,你可以用一块石头杀死两只鸟:

function FontAwesome_icons() {
echo '<link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css"  rel="stylesheet">';
}

add_action('admin_head', 'FontAwesome_icons');
add_action('wp_head', 'FontAwesome_icons');

参考:https://cnpagency.com/blog/3-ways-to-use-icon-fonts-in-your-wordpress-theme-admin/

答案 1 :(得分:0)

在自定义帖子类型插件中,您无法添加字体真棒图标。您必须使用dashicon类名或图标图像URL。

参考。对于dashicon类 - https://developer.wordpress.org/resource/dashicons/

您可以从不同的网站下载图标并使用它。 参考。 - http://www.flaticon.com/packs/font-awesome

我希望它对你有用。

答案 2 :(得分:0)

您可以将download字体真棒图标作为png并上传到wordpress并写入完整网址http://www.example.com/wp-content/uploads/2014/11/your-cpt-icon.png 像上面......

图标大小必须为20px ...

或者你可以使用dashicon。它会自动支持dashicons。

点击此图片http://dev.savivatechnologies.com/hpa/wp-content/uploads/2017/07/dashicon.png

希望这会对你有帮助......

答案 3 :(得分:0)

在您的帖子类型数组中添加fontawsome类,如下所示:

array(
'menu_icon' => 'dashicons-fa fa-book', /* the icon for the custom post type menu. uses built-in dashicons (CSS class name) */
);

然后将这些钩子添加到您的functions.php中

add_filter( 'sanitize_html_class', function ( $sanitized, $class, $fallback ) {

    if ( strpos( $class, 'fa' )
         || strpos( $class, 'fas' )
         || strpos( $class, 'fal' )
         || strpos( $class, 'fab' )
         || strpos( $class, 'far' )
    ) {
        $class = str_replace( 'dashicons-', '', $class );

        return $class;

    }

    return $sanitized;

}, 0, 3 );

并在您的管理文档中添加可怕的字体:

function fontawesome_dashboard() {
    wp_enqueue_style('custom-style', get_template_directory_uri().'/assets/styles/all.min.css');
    wp_add_inline_style( 'custom-style', '.fa:before,.fas:before,.fal:before,.fab:before,.far:before{font-family:inherit!important;}' );

}
add_action('admin_init', 'fontawesome_dashboard');
相关问题