Files
wordpress-kratos-yang/inc/theme-custom-code.php
T

68 lines
1.8 KiB
PHP
Raw Normal View History

<?php
/**
* 自定义代码(CSS / JS)
*
* 这两段代码存在主题选项里(数据库 wp_options 的 kratos 项),不存主题目录。
* 原因:WordPress 升级/更新主题时会**清空整个主题目录**再解压
* (wp-admin/includes/class-theme-upgrader.php 里 clear_destination = true,
* 随后 delete_old_theme() 递归删除),写在主题目录里的任何自定义文件都会丢。
* 放进选项表就与主题文件解耦,升级、重装、换主题目录名都不影响。
*
* @author Yongquan Yang <yangyq.net>
* @license MIT License
*/
/**
* 默认自定义 CSS。
*
* 历史沿革:这些规则原本放在主题目录下的一个 custom 子目录里,是该主题早期的
* 「自定义样式」入口。改成配置项后,把它作为默认值,保证切换瞬间站点外观
* 完全不变;同时 `恢复默认` 也能拿回这套样式。
*
* 想彻底清掉:在后台把「自定义 CSS」清空保存即可(空值会覆盖这里的默认值)。
*/
function yang_default_custom_css()
{
return <<<'CSS'
.article .content p{ text-indent:2em }
.k-main .details .article .content h2 {
margin: 16px -16px;
padding: 0 10px;
border-left: 5px solid #00a2ff;
background-color: rgba(243, 243, 243, 0.7);
font-size: 20px;
line-height: 41px;
}
ul{
margin-left:2em;
}
ol{
margin-left:2em;
}
ol > li{
line-height: 1.8;
}
ul > li{
line-height: 1.8;
}
CSS;
}
/**
* 取自定义 CSS(未设置时回退到默认值)
*/
function yang_custom_css()
{
$css = kratos_option('g_custom_css', yang_default_custom_css());
return is_string($css) ? $css : '';
}
/**
* 取自定义 JS(未设置时为空)
*/
function yang_custom_js()
{
$js = kratos_option('g_custom_js', '');
return is_string($js) ? $js : '';
}