我创建了一个带有管理页面的WordPress插件,人们可以在其中输入自己的值来对其进行自定义。
选项之一是自定义插件,在该插件中输入十六进制代码,我想将此值映射到我的样式表。我知道$ mainstylecolor的值是正确的,因为我在另一个页面上回显了它,并且确实从数据库中获取了该值。
问题似乎是该值必须在样式表的顶部用双引号引起来,但是如果我将其用双引号引起来,则在调用该变量时它只会打印行而不是值。
因此,总结一下,我需要能够从数据库中获取一个值,然后在我的styles.php中使用它。
如果有人可以告诉我我该怎么做,这将是我插件的最后一部分。
<?php
header("Content-type: text/css");
$mainstylecolor = esc_attr( get_option( 'ik_plugin_color' ) );
?>
<style>
.sponsor-main-button{
padding: 15px 25px !important;
border: 2px solid <?php echo $mainstylecolor; ?>;
font-weight: bold !important;
text-transform: uppercase !important;
letter-spacing: 2px !important;
font-size: 16px!important;
color: #fff !important;
background: <?php echo $mainstylecolor; ?>;
min-width: 50%;
text-align: center;
}
</style>
答案 0 :(得分:0)
关于错误:在这种情况下,最好在wp-config.php中打开调试(但不要忘了之后:-)关闭
define( 'WP_DEBUG', true );
但是我怀疑,如果不更改.htaccess,这是行不通的,您当然要避免在插件中使用它。 explanation
根据样式表的大小,您可以直接在wordpress的wp_head钩子上直接内联输出。
function myplugin_css() {
$mainstylecolor = esc_attr( get_option( 'ik_plugin_color' ) );
?>
<!-- myplugin style -->
<style>
.sponsor-main-button{
padding: 15px 25px !important;
border: 2px solid <?= $mainstylecolor; ?>;
font-weight: bold !important;
text-transform: uppercase !important;
letter-spacing: 2px !important;
font-size: 16px!important;
color: #fff !important;
background: <?= $mainstylecolor; ?>;
min-width: 50%;
text-align: center;
}
</style>
<?php
}
add_action('wp_head', 'myplugin_css');