如何在Wordpress中正确出列某些Elementorcss文件

我使用 Elementor 来构建我的网站,并且有很多我没有使用的功能,但是在我的网站的每个页面上都加载了很多功能。所以我决定将我没有在我的子主题的 functions.php 中使用的 css 文件出列,并将我只部分使用的 css 文件出列,用文件的“清理”版本替换它们。

我使用 Elementor 来构建我的网站,并且有很多我没有使用的功能,但是在我的网站的每个页面上都加载了很多功能。所以我决定将我没有在我的子主题的 functions.php 中使用的 css 文件出列,并将我只部分使用的 css 文件出列,用文件的“清理”版本替换它们。

这就是我想要开始做的:

function adg_dequeue_unnecessary_files() {
    wp_dequeue_style( 'elementor-frontend' ); // remove Elementor's custom-frontend.min.css
        wp_deregister_style( 'elementor-frontend' );
    wp_register_style( 'new-elementor-frontend-css', get_stylesheet_directory_uri() . '/custom-frontend.min.css' ); // Purified replacement for Elementor's custom-frontend.min.css
        wp_enqueue_style( 'new-elementor-frontend-css' );
}
add_action( 'wp_enqueue_scripts', 'adg_dequeue_unnecessary_files' );

但是,虽然我的功能的第二部分很好地添加了我的新自定义 css 文件,但第一部分删除了几乎 10 个其他 Elementor 的 css 文件以及我真正想要出列的文件。

这是要出列的文件列表:

custom-frontend.min.css

post-1501.css(这是我在进行这些更改时正在查看的页面的 css 文件)

前端 legacy.min.css

post-1396.css(一些全局 Elementor 的 css)

post-3556.css(这个和下面的 5 是我在我的网站上使用的插件的模板)

post-4473.css

post-5653.css

post-3489.css

post-3464.css

post-3458.css

我猜它与处理程序 'elementor-frontend' 不正确有关。custom-frontend.min.css 文件在 HTML 代码的链接标记中有 'elementor-frontend-css' ID,所以我从那里猜测处理程序。

有谁知道我怎么能出队只自定义 frontend.min.css 文件?

之后,我想出列这些文件以及:

animations.min.css

elementor-icons.min.css

global.css

前端 legacy.min.css

swiper.min.js

我已经浏览了几天,我开始感到失落,所以任何帮助将不胜感激!

2

您可以使用wp_deregister_stylewp_dequeue_style将 Elementor CSS 文件出列。为此,您需要传递 CSS 文件句柄名称。您可以使用以下代码将 Elementor 插件global.css文件出列。

function dequeue_elementor_global__css() {
  wp_dequeue_style('elementor-global');
  wp_deregister_style('elementor-global');
}
add_action('wp_print_styles', 'dequeue_elementor_global__css', 9999);

这里elementor-global是 global.css 文件的句柄名称。您可以通过样式表 ID 获取任何文件句柄名称。
例如:如果任何样式表 ID 是elementor-global-css,则此文件句柄将是elementor-global

1

我的理解是,所有 Elementor 前端样式,例如你的 post-1234.css 文件,是 'elementor-frontend' 的孩子,这意味着如果你卸载它,他们都不会加载。

如果您加载具有相同名称的新的,优化的 frontend.min.css 文件,那么它应该工作。

例如

function adg_dequeue_unnecessary_files() {
    wp_dequeue_style( 'elementor-frontend' ); // remove Elementor's custom-frontend.min.css
        wp_deregister_style( 'elementor-frontend' );
    wp_register_style( 'elementor-frontend', get_stylesheet_directory_uri() . '/custom-frontend.min.css' ); // Purified replacement for Elementor's custom-frontend.min.css
        wp_enqueue_style( 'elementor-frontend' );
}
add_action( 'wp_enqueue_scripts', 'adg_dequeue_unnecessary_files' );

另外。你不能只将你的 custom-frontend.min.css 添加到你的子主题中的相关位置,它会默认覆盖父主题版本吗?

-1

这似乎工作。在几页和帖子上测试:

add_action( 'elementor/frontend/after_enqueue_styles', function() { 
    wp_deregister_style( 'elementor-frontend' );
    wp_dequeue_style( 'elementor-frontend' );
    wp_register_style( 'elementor-frontend', get_stylesheet_directory_uri() . '/ets/css/custom-elementor-front-end.css' );
   wp_enqueue_style( 'elementor-frontend', get_stylesheet_directory_uri() . '/ets/css/custom-elementor-front-end.css' );
} );

本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处

(880)
如何查找和测量图像中的弧长(measure an arc)
上一篇
从电子应用程序调用.NET核心库
下一篇

相关推荐

  • css预编译器: center;}

    CSS预编译器是一种用于构建CSS的工具,它可以将CSS代码转换为更易于管理和维护的格式。它们可以使CSS代码更加灵活,更易于重用,并且可以帮助开发人员更轻松地组织和管理CSS代码。…

    2023-01-05 06:29:43
    0 61 70
  • linux切换到超级用户:```shecho 'Hello World' > hello_world.txt```

    Linux切换到超级用户的方法有两种:使用su命令:…

    2023-02-20 00:24:31
    0 97 11
  • xcode代码格式化快捷键:使用Command + I快速格式化Xcode代码

    格式化的方法格式化的方法Xcode代码格式化快捷键:Option+Command+F…

    2023-02-06 04:35:36
    0 78 54
  • plc和java哪个难学比较学习难度的对比

    PLC和Java哪个难学这个问题的答案取决于你的背景和目标。PLC是一种工业控制系统,它使用专用的编程语言来控制机器和设备。它的编程语言比较复杂,而且不同的厂家会有不同的语言,所以学习PLC的难度会比较大。而Java是一种通用的编程语言,它的语法比较简单,而且可以跨平台使用,所以学习Java的难度会比PLC要小一些。…

    2023-03-22 09:22:12
    0 49 27
  • linux的共享文件夹在哪个目录:Linux共享文件夹在/etc/samba目录下

    Linux的共享文件夹在/var/lib/samba/目录下,查看该目录下的文件可以使用以下代码:ls /var/lib/samba/…

    2023-01-21 15:31:10
    0 77 72
  • vb如何编写程序代码Private Sub Form_Load() ' 设置窗口标题 Me.Caption = He

    示例示例VB程序代码的编写是通过使用Visual Basic编程语言来实现的。下面是一个简单的VB程序代码示例:'示例代码…

    2023-03-14 15:57:06
    0 47 71
  • code键 A Guide to Success

    示例示例code键是一个特殊的键,它可以用来输入代码。它通常位于键盘的右上角,并且有一个特殊的图标,如“#”或“@”。下面是一个简单的代码示例,使用code键来输入代码:…

    2023-02-13 08:43:06
    0 15 80
  • type c接口是啥改变你的充电体验

    示例示例Type C接口是一种新型的USB连接器,它可以支持更高的数据传输速度,比传统的USB 0接口更快。与传统的USB接口不同,Type C接口可以在两端都使用,无需额外的翻转,使连接更加方便快捷。下面是一个使用Type C接口的代码示例:…

    2023-01-12 02:06:09
    0 92 59

发表评论

登录 后才能评论

评论列表(39条)