【发布时间】:2020-06-24 01:40:00
【问题描述】:
我正在使用 WordPress 反垃圾邮件程序代码,来自他们的代码参考:
https://developer.wordpress.org/reference/functions/antispambot/
它工作正常,但我想设置代码显示的电子邮件地址的样式。如果混淆的电子邮件地址位于页脚中,我想应用特定样式,但如果混淆的电子邮件地址位于页面正文中,例如,我想应用不同的样式。
我已经尝试为标签添加标题属性,如下面的代码所示:
function wpcodex_hide_email_shortcode( $atts , $content = null ) {
if ( ! is_email( $content ) ) {
return;
}
return '<a href="mailto:' . antispambot( $content ) . '" title="encrypted-email">' . antispambot(
$content ) . '</a>';
}
add_shortcode( 'email', 'wpcodex_hide_email_shortcode' );
然后使用以下 CSS 设置样式:
/* GENERAL STYLE FOR ENCRYPTED EMAILS */
a[title="encrypted-email"]{
color:#4472e6 !important;
text-decoration:none !important;
}
a[title="encrypted-email"]:hover{
text-decoration:underline !important;
}
/* STYLE FOR ENCRYPTED EMAILS IN FOOTER */
.fusion-footer-widget-area .custom-html-widget a[title="encrypted-email"]{
color:#ff0000;
text-decoration:none !important;
}
.fusion-footer-widget-area .custom-html-widget a[title="encrypted-email"]:hover{
color:#e4d06f;
}
但是,使用上面的 CSS,所有加密电子邮件,包括页脚中的加密电子邮件,都采用“常规”样式。
我想知道这种方法是否是为页面不同部分(例如正文与页脚)中的加密电子邮件设置不同 CSS 样式的最佳方法。
另外,我的 CSS 是否正确?
更新
生成的HTML如下:
<ul style="list-style-type:none; margin:0; padding:0;">
<li style="font-size:16px; margin-bottom:0px;"><a
href="mailto:wbu@bd"
title="encrypted-email">wbu@bd</a></li>
</ul>
【问题讨论】:
-
您能否更新您的问题以包含短代码生成的 HTML?如果我们无法准确查看 HTML 的外观,我们将无法帮助您设置 HTML 样式:)
-
@FluffyKitten 添加了生成的 HTML。