gpt4 book ai didi

css - 从激活的 WordPress 插件应用 CSS 文件

转载 作者:行者123 更新时间:2023-11-28 02:24:16 24 4
gpt4 key购买 nike

我是 wordpress 的新手,想知道从已安装和激活的插件中添加 css 的最佳方法。我有一个名为“social-media”的激活插件,在该插件中我创建了一个名为“social-login-style.css”的 css 文件

我想包含这个css文件并应用样式到我的内容。我应该如何在任何页面中添加 css 文件,以便我可以看到效果。

简而言之,我想在 wp-login.php 文件中添加 social-login-style.css

最佳答案

无论是主题还是插件,css还是js,任何自定义添加,wp_enqueue_scripts都是你唯一需要的acton。

https://codex.wordpress.org/Plugin_API/Action_Reference/wp_enqueue_scripts

function additional_custom_styles() {

/* Enqueue The Styles */
wp_enqueue_style( 'custom-login-style', plugins_url( 'social-login-style.css', __FILE__ ) );

}
add_action( 'wp_enqueue_scripts', 'additional_custom_styles' );

如果您只在登录屏幕上添加它,请使用以下条件,

if ( $GLOBALS['pagenow'] === 'wp-login.php' ) {
// We're on the login page!
}

希望这对您有所帮助:)

更新

请检查login_enqueue_scripts。它旨在仅将自定义脚本添加到登录页面。无需任何登录条件即可正常工作。

https://codex.wordpress.org/Plugin_API/Action_Reference/login_enqueue_scripts

关于css - 从激活的 WordPress 插件应用 CSS 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48031936/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com