从WordPress 2.5版本开始,我们便能够方便地在正文中插入其内置的原生相册(调用说明),但同时它也会在文章中自动插入对相册样式控制的CSS代码。当然这样会让我们的相册看起来漂亮点,但是,这样会让WordPress中带有相册的页面不能通过XHTML 1.0认证。
要去除WordPress自动插入的相册样式代码,我们需要在functions.php文件中加入如下代码:
########################################################
# 去除WordPress自动插入原生相册样式代码
########################################################
function remove_css_gal() {
return "\n" . '<div class="gallery">';//ici vous pouvez changer de classe
}
add_filter( 'gallery_style', 'remove_css_gal', 9 );
当然你可以把上面的代码做成插件使用,这个就不那么重要了。使用上面代码后,再次查看带有相册的页面的源代码,是不是已经发现原来的这段自动插入的代码不见了?
<style type='text/css'>
.gallery {
margin: auto;
}
.gallery-item {
float: left;
margin-top: 10px;
text-align: center;
width: 33%;
}
.gallery img {
border: 2px solid #cfcfcf;
}
.gallery-caption {
margin-left: 0;
}
</style>
<!-- see gallery_shortcode() in wp-includes/media.php -->
最后别忘记在你的style.css文件中重新加上被去掉的代码,否则,the sky will fall on your head