在php中设置多个链接的样式

时间:2019-06-18 18:01:18

标签: php html css wordpress

我有一些PHP可以在我的网站上用于样式化链接。但是,当我尝试使用相同的代码以其他方式设置其他链接的样式时,则会中断我的网站。

例如,我有:

add_action('admin_head', 'my_custom_css');
function my_custom_css() {
echo '<style>
.events-dashboard1 {background-color: green;}
</style>';
}

这可行,但是当我尝试像这样复制时:

add_action('admin_head', 'my_custom_css');
function my_custom_css() {
echo '<style>
.post-job1.post-event1 {background-color: #e5f25c; color: white
!important;}
</style>';
}

站点中断。我调查发现,使用类似的多个类行不通。但是,如果我只用1个类重新发布相同的php代码,它就会中断。尝试更改格式-无。

HTML:

<div id="adminmenuwrap">
<ul id="adminmenu">
<li class="wp-first-item wp-has-submenu wp-has-current-submenu wp- 
menu-open menu-top menu-top-first menu-icon-dashboard menu-top. 
first" id="menu-dashboard">
<a href='index.php' class="wp-first-item 
wp-has-submenu wp-has-current-submenu wp-menu-open menu-top menu- 
top-first menu-icon-dashboard menu-top-first">
<div class="wp-menu- 
arrow"><div></div>
</div><div class='wp-menu-image dashicons-before 
dashicons-dashboard'><br /></div>
<div class='wp-menu- 
name'>Dashboard</div>
</a>
<ul class='wp-submenu wp-submenu-wrap'>
<li class='wp-submenu-head' aria- 
hidden='true'>Dashboard</li>
            <li class="wp-first-item current">.
                <a href='index.php' class="wp-first-item current" 
aria- current="page">Home</a></li>
            <li><a href='update-core.php'>Updates 
<span class='update-plugins count-37'><span class='update. 
count'>37</span></span></a></li>
            <li class="jobs-dashboard1"><a 
href='https://adsler.co.uk/jobs-dashboard/' class="jobs. 
dashboard1">Jobs</a></li>
            <li class="post-job1"><a 
href='https://adsler.co.uk/post-a-job/' class="post-job1">Post A 
Job</a></li>
            <li class="events-dashboard1"><a 
 href='https://adsler.co.uk/your-events-dashboard/' class="events. 
 dashboard1">Events</a></li>
            <li class="post-event1"><a 
href='https://adsler.co.uk/post-an-event/' class="post-event1">Post 
An Event</a></li>
        </ul>
    </li>

所以现在我有四个链接,其中两个我不能设置样式,另外两个是上面的代码和下面的代码的样式。每个一个:

function custom_admin_css() { echo ' <style> .jobs- 
dashboard1 { background-color: green; } </style>'; } 
add_action('admin_head', 'custom_admin_css');

1 个答案:

答案 0 :(得分:0)

只需将所有样式放在同一个标​​签下即可。看来您试图两次使用相同的功能,但是您不能这样做。

add_action('admin_head', 'my_custom_css');
function my_custom_css() {
echo '<style>
.events-dashboard1 {background-color: green;}
.post-job1, .post-event1 {background-color: #e5f25c; color: white
!important;}

/* Any other CSS you have put here */

</style>';
}

最终,您应该做的是创建一个CSS文件。将您的CSS放入其中。然后将其入队。像这样。

admin-styles.css

.events-dashboard1 {background-color: green;}
.post-job1, .post-event1 {background-color: #e5f25c; color: white
!important;}

/* the rest of your CSS */

排队文件

add_action('admin_head', 'my_custom_css');
function my_custom_css() {
  wp_enqueue_style('admin-css', '/path/to/file/admin-styles.css');
}