css 字段定义模糊_使用自定义字段将自定义CSS嵌入到您的单个帖子中

css 字段定义模糊

There will be times when you want to use custom CSS in your single posts. In this tutorial we will share one of the ways that you can easily embed custom CSS in your single posts in WordPress with the use of Custom Fields.

有时候您想在单个帖子中使用自定义CSS。 在本教程中,我们将分享一种方法,您可以使用“自定义字段”轻松地将自定义CSS嵌入WordPress的单个帖子中。

First you will need to open your header.php and insert this code somewhere in between <head></head> codes.

首先,您需要打开header.php并将此代码插入<head> </ head>代码之间的某个位置。

<?php if (is_single()) {
$customstyle = get_post_meta($post->ID, 'customstyle', true);
if (!empty($customstyle)) { ?>
<style type="text/css">
<?php echo $customstyle; ?>
<style>
<?php }
} ?>

<?php if(is_single()){
$ customstyle = get_post_meta($ post-> ID,'customstyle',true);
如果(!empty($ customstyle)){?>
<style type =“ text / css”>
<?php echo $ customstyle; ?>
<样式>
<?php}
}?>

Once you have done that you can add a custom field in each post with the name customstyle and add the css codes in there.

完成此操作后,您可以在每个帖子中添加一个名为customstyle的自定义字段,并在其中添加css代码。

For example if you want the a certain image to have border you can add:

例如,如果您希望某个图像具有边框,则可以添加:

#coolimageclass{border: 5px solid #ccc;}

#coolimageclass {边框:5像素实心#ccc;}

Use the format above and you now have custom CSS for your single posts.

使用上面的格式,您现在就可以为单个帖子添加自定义CSS。

翻译自: https://www.wpbeginner.com/wp-themes/embed-custom-css-in-your-single-posts-with-custom-fields/

css 字段定义模糊

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值