我是wordpress的新手,想知道从已安装和激活的插件添加css的最佳方法。
我有一个名为“social-media
”的激活插件,在该插件中我创建了一个名为“social-login-style.css
”的css文件
我希望{c}文件include
和我的内容apply style
。我应该如何在任何页面中添加css文件,以便我可以看到效果。
简而言之,我想在social-login-style.css
文件中添加wp-login.php
。
答案 0 :(得分:0)
无论是主题还是插件,css或js,任何自定义添加, private void EngageAutoRenewLock(BrokeredMessage message, CancellationTokenSource renewLockCancellationTokenSource)
{
var renewalThread = Task.Factory.StartNew(() =>
{
Trace(string.Format("Starting lock renewal thread for MsgID {0}", message.MessageId));
while (!renewLockCancellationTokenSource.IsCancellationRequested)
{
// we use Sleep instead of Task.Delay to avoid get an exception when token is cancelled
System.Threading.Thread.Sleep(30000);
// check again after sleeping
if (!renewLockCancellationTokenSource.IsCancellationRequested)
{
try
{
// renewlock wraps a RenewLockAsync() call
message.RenewLock();
}
catch (Exception ex)
{
/* Do Nothing.
This exception can happen due the async nature of the RenewLock Operation (async Begin/End), it is possible we
completed/abandoned/deadlettered the message in the main thread in the middle of the RenewLock operation.
Additionally, we should keep retrying to renew lock until renewLockCancellationTokenSource has ben signaled.
This will allow to handle other transient renewal issues. */
Trace(string.Format("Lock renewal failed due an exception for MsgID {0} - {1}", message.MessageId, ex.Message));
}
Trace(string.Format("Lock renewed MsgID {0}", message.MessageId));
}
else
{
Trace(string.Format("Lock renewed MsgID {0} not happened due IsCancellationRequested == true", message.MessageId));
}
}
Trace(string.Format("Lock renewal has been cancelled by cancellationToken (ok) for MsgID {0}", message.MessageId));
}, renewLockCancellationTokenSource.Token);
}
都是您需要的唯一活动。
https://codex.wordpress.org/Plugin_API/Action_Reference/wp_enqueue_scripts
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!
}
。它旨在仅将自定义脚本添加到登录页面中。在没有任何登录条件的情况下运行良好。
https://codex.wordpress.org/Plugin_API/Action_Reference/login_enqueue_scripts
答案 1 :(得分:0)
不说你想要实现的目标是不可能的,但肯定是违反了WordPress的设计方式。插件应该是添加或修改WordPress工作方式的模块。插件的文件夹应该只保存与插件有关的文件,如果是公共插件,则其内容由版本控制(SVN)系统控制。
简而言之,无论插件是否处于活动状态,向现有插件添加文件都不会产生任何影响。而且你不应该把文件添加到你自己没有开发过的插件中。
要在登录页面上加载CSS文件,应按照codex的Customizing Login Form页面中的说明向login_enqueue_scripts
添加操作挂钩。样式表本身应放在自定义插件中(您可以为用例创建)或在当前主题文件夹中。