WordPress小技巧 纯代码为文章编辑添加彩色美化框及彩色按钮
![]() | ![]() | ![]() | ![]() |
| 【性价之王】 | 【线路之王】 | 【价格之王】 | 【配置之王】 |
| 【免费之王】 | 【香港首推】 | 【梯子之王】 | 【独服之王】 |

WordPress的文本编辑功能确实很平常,没有什么新意或者说是亮点,之前蜗牛为大家介绍过比较实用的表格插件(WordPress简便实用的表格插件推荐 WP Tabel Tag Gen汉化版)和纯代码添加下载按钮(WordPress小技巧 通过纯代码为文章编辑添加链接按钮),都是个人在使用过程当中绝得好用才分享给大家的。WP Tabel Tag Gen可以根据自己的需要往文章内插入表格、纯代码添加下载按钮可以让你文章的下载按钮更美观。此次蜗牛再为大家分享一个WordPress美化小技巧,纯代码为文章添加彩色美化框、及闪光按钮,并且在撰写新文章文本编辑模式添加相关按钮,后续直接点击按钮插入即可。
一、效果展示使用本文中介绍的方法,大家都可以达到以下效果。
1、撰写新文章的文本编辑按钮展示。
2、文本彩色美化框展示。
绿色提示框
红色提示框
黄色提示框
灰色提示框
蓝色提示框
黑色提示框
虚线提示框
绿边提示框
红边提示框
3、按钮展示。
[sgbtn_blue h=”]点击购买[/sgbtn_blue]
[sgbtn_red h=”]点击购买[/sgbtn_red]
[sgbtn_orange h=”]点击购买[/sgbtn_orange]
[sgbtn_lv h=”]点击购买[/sgbtn_lv]
[gb h=”]点击购买[/gb]
[bb h=”]点击购买[/bb]
[yb h=”]点击购买[/yb]
二、实现方法1、在主题functions.php文件中添加下面两段代码。
function toz($atts, $content=null){ return \'<div id=\"sc_notice\">\'.$content.\'</div>\';}add_shortcode(\'v_notice\',\'toz\');function toa($atts, $content=null){ return \'<div id=\"sc_error\">\'.$content.\'</div>\';}add_shortcode(\'v_error\',\'toa\');function toc($atts, $content=null){ return \'<div id=\"sc_warn\">\'.$content.\'</div>\';}add_shortcode(\'v_warn\',\'toc\');function tob($atts, $content=null){ return \'<div id=\"sc_tips\">\'.$content.\'</div>\';}add_shortcode(\'v_tips\',\'tob\');function tod($atts, $content=null){ return \'<div id=\"sc_blue\">\'.$content.\'</div>\';}add_shortcode(\'v_blue\',\'tod\');function toe($atts, $content=null){ return \'<div id=\"sc_black\">\'.$content.\'</div>\';}add_shortcode(\'v_black\',\'toe\');function tof($atts, $content=null){ return \'<div id=\"sc_xuk\">\'.$content.\'</div>\';}add_shortcode(\'v_xuk\',\'tof\');function tog($atts, $content=null){ return \'<div id=\"sc_lvb\">\'.$content.\'</div>\';}add_shortcode(\'v_lvb\',\'tog\');function toh($atts, $content=null){ return \'<div id=\"sc_redb\">\'.$content.\'</div>\';}add_shortcode(\'v_redb\',\'toh\');function toi($atts, $content=null){ return \'<div id=\"sc_orange\">\'.$content.\'</div>\';}add_shortcode(\'v_orange\',\'toi\');function sg_blue($atts, $content = null) { extract(shortcode_atts(array( \"h\" => \'http://\' ) , $atts)); return \'<a class=\"sgbtn_blue\" h=\"\' . $h . \'\" target=\"_blank\" rel=\"nofollow\">\' . $content . \'</a>\';}add_shortcode(\'sgbtn_blue\', \'sg_blue\');function sg_red($atts, $content = null) { extract(shortcode_atts(array( \"h\" => \'http://\' ) , $atts)); return \'<a class=\"sgbtn_red\" h=\"\' . $h . \'\" target=\"_blank\" rel=\"nofollow\">\' . $content . \'</a>\';}add_shortcode(\'sgbtn_red\', \'sg_red\');function sg_orange($atts, $content = null) { extract(shortcode_atts(array( \"h\" => \'http://\' ) , $atts)); return \'<a class=\"sgbtn_orange\" h=\"\' . $h . \'\" target=\"_blank\" rel=\"nofollow\">\' . $content . \'</a>\';}add_shortcode(\'sgbtn_orange\', \'sg_orange\');function sg_lv($atts, $content = null) { extract(shortcode_atts(array( \"h\" => \'http://\' ) , $atts)); return \'<a class=\"sgbtn_lv\" h=\"\' . $h . \'\" target=\"_blank\" rel=\"nofollow\">\' . $content . \'</a>\';}add_shortcode(\'sgbtn_lv\', \'sg_lv\');function toj($atts, $content=null) { extract(shortcode_atts(array(\"h\" => \'http://\'), $atts)); return \'<a class=\"bluebtn\" h=\"\' . $h . \'\" target=\"_blank\" rel=\"nofollow\">\' .$content.\'</a>\';}add_shortcode(\'bb\' , \'toj\' );function tok($atts, $content=null) { extract(shortcode_atts(array(\"h\" => \'http://\'), $atts)); return \'<a class=\"yellowbtn\" h=\"\' . $h . \'\" target=\"_blank\" rel=\"nofollow\">\' .$content.\'</a>\';}add_shortcode(\'yb\' , \'tok\' );function tol($atts, $content=null) { extract(shortcode_atts(array(\"h\" => \'http://\'), $atts)); return \'<a class=\"greenbtn\" h=\"\' . $h . \'\" target=\"_blank\" rel=\"nofollow\">\' .$content.\'</a>\';}add_shortcode(\'gb\' , \'tol\' );注意:复制后请修改下面代码中的“【”为“[”,否则按钮部分无效。
add_action(\'after_wp_tiny_mce\', \'bolo_after_wp_tiny_mce\'); function bolo_after_wp_tiny_mce($mce_settings) { ?> <script type=\"text/javascript\"> QTags.addButton( \'v_notice\', \'绿框\', \'<div id=\"sc_notice\">绿色提示框</div>\\n\', \"\" ); QTags.addButton( \'v_error\', \'红框\', \'<div id=\"sc_error\">红色提示框</div>\\n\', \"\" ); QTags.addButton( \'v_warn\', \'黄框\', \'<div id=\"sc_warn\">黄色提示框</div>\\n\', \"\" ); QTags.addButton( \'v_tips\', \'灰框\', \'<div id=\"sc_tips\">灰色提示框</div>\\n\', \"\" ); QTags.addButton( \'v_blue\', \'蓝框\', \'<div id=\"sc_blue\">蓝色提示框</div>\\n\', \"\" ); QTags.addButton( \'v_black\', \'黑框\', \'<div id=\"sc_black\">黑色提示框</div>\\n\', \"\" ); QTags.addButton( \'v_xuk\', \'虚线\', \'<div id=\"sc_xuk\">虚线提示框</div>\\n\', \"\" ); QTags.addButton( \'v_lvb\', \'绿边\', \'<div id=\"sc_lvb\">绿边提示框</div>\\n\', \"\" ); QTags.addButton( \'v_redb\', \'红边\', \'<div id=\"sc_redb\">红边提示框</div>\\n\', \"\" ); QTags.addButton( \'sgbtn_blue\', \'蓝色闪光\', \"【sgbtn_blue h=\'\']点击购买\", \"[/sgbtn_blue]\" ); QTags.addButton( \'sgbtn_red\', \'红色闪光\', \"【sgbtn_red h=\'\']点击购买\", \"[/sgbtn_red]\" ); QTags.addButton( \'sgbtn_orange\', \'黄色闪光\', \"【sgbtn_orange h=\'\']点击购买\", \"[/sgbtn_orange]\" ); QTags.addButton( \'sgbtn_lv\', \'绿色闪光\', \"【sgbtn_lv h=\'\']点击购买\", \"[/sgbtn_lv]\" ); QTags.addButton( \'gb\', \'绿色按钮\', \"【gb h=\'\']点击购买\", \"[/gb]\" ); QTags.addButton( \'bb\', \'蓝色按钮\', \"【bb h=\'\']点击购买\", \"[/bb]\" ); QTags.addButton( \'yb\', \'黄色按钮\', \"【yb h=\'\']点击购买\", \"[/yb]\" ); function bolo_QTnextpage_arg1() { } </script> <?php }2、修改CSS代码。我们在主题的style.css文件中或者main.css文件中添加下面代码。
如果文本美化框前面的图标不正常显示,请把下面代码中“img/sc_notice.png”等4个图片改成图片网址即可正常显示。
#sc_notice { color: #7da33c; background: #ecf2d6 url(\'img/sc_notice.png\') -1px -1px no-repeat; border: 1px solid #aac66d; overflow: hidden; margin: 10px 0; padding: 15px 15px 15px 35px; }#sc_warn { color: #ad9948; background: #fff4b9 url(\'img/sc_warn.png\') -1px -1px no-repeat; border: 1px solid #eac946; overflow: hidden; margin: 10px 0; padding: 15px 15px 15px 35px; }#sc_error { color: #c66; background: #ffecea url(\'img/sc_error.png\') -1px -1px no-repeat; border: 1px solid #ebb1b1; overflow: hidden; margin: 10px 0; padding: 15px 15px 15px 35px; }#sc_tips { color: #777; background: #eaeaea url(\'img/sc_tips.png\') -1px -1px no-repeat; border: 1px solid #ccc; overflow: hidden; margin: 10px 0; padding: 15px 15px 15px 35px;}#sc_blue { color: #1ba1e2; background: rgba(27, 161, 226, 0.26) url(\'img/sc_blue.png\') -1px -1px no-repeat; border: 1px solid #1ba1e2; overflow: hidden; margin: 10px 0; padding: 15px 15px 15px 35px;}#sc_black { border-width: 1px 4px 4px 1px; border-style: solid; border-color: #3e3e3e; margin: 10px 0; padding: 15px 15px 15px 35px;}#sc_xuk { border: 2px dashed rgb(41, 170, 227); background-color: rgb(248, 247, 245); margin: 10px 0; padding: 15px 15px 15px 35px;}#sc_lvb { margin: 10px 0; padding: 10px 15px; border: 1px solid #e3e3e3; border-left: 2px solid #05B536; background: #FFF;}#sc_redb { margin: 10px 0; padding: 10px 15px; border: 1px solid #e3e3e3; border-left: 2px solid #ED0505; background: #FFF;}#sc_organge { margin: 10px 0; padding: 10px 15px; border: 1px solid #e3e3e3; border-left: 2px solid #EC8006; background: #FFF;}[class*=sgbtn]{display:inline-block;text-indent:0;position:relative;color:#fff;padding:0 10px 0 10px;min-width:160px;height:38px;line-height:38px;opacity:.8;text-align:center;font-family:Ubuntu,sans-serif;font-size:15px;text-decoration:none;border-radius:2px;overflow:hidden;-webkit-transition:all .15s ease-in;transition:all .15s ease-in}[class*=sgbtn]:before{content:\'\';position:absolute;background:#fff;width:25px;height:50px;top:0;left:-45px;opacity:.3;-webkit-transition:all .25s ease-out;transition:all .25s ease-out;-webkit-transform:skewX(-25deg);transform:skewX(-25deg)}[class*=sgbtn]:hover{opacity:.65}[class*=sgbtn]:hover:before{width:45px;left:205px}.sgbtn_blue{color:#fff;background:#1cb2f5}.sgbtn_red{color:#fff;background:#C00}.sgbtn_orange{color:#fff;background:#F90}.sgbtn_lv{color:#fff;background:#096}a[class*=sgbtn]{color:#fff}a[class*=sgbtn]:hover{color:#fff}.greenbtn{-moz-box-shadow:0 10px 14px -7px #3e7327;-webkit-box-shadow:0 10px14px -7px #3e7327;box-shadow:0 10px 14px -7px#3e7327;background:-webkit-gradient(linear,left top,leftbottom,color-stop(0.05,#77b55a),color-stop(1,#72b352));background:-moz-linear-gradient(top,#77b55a 5%,#72b352100%);background:-webkit-linear-gradient(top,#77b55a 5%,#72b352100%);background:-o-linear-gradient(top,#77b55a 5%,#72b352100%);background:-ms-linear-gradient(top,#77b55a 5%,#72b352100%);background:linear-gradient(to bottom,#77b55a 5%,#72b352100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=\'#77b55a\',endColorstr=\'#72b352\',GradientType=0);background-color:#77b55a;-moz-border-radius:4px;-webkit-border-radius:4px;border-radius:4px;border:1px solid#4b8f29;display:inline-block;cursor:pointer;color:#fff !important;;font-family:arial;font-size:13px;font-weight:bold;padding:6px12px;text-decoration:none;text-shadow:0 1px 0#5b8a3c}.greenbtn:hover{background:-webkit-gradient(linear,left top,leftbottom,color-stop(0.05,#72b352),color-stop(1,#77b55a));background:-moz-linear-gradient(top,#72b352 5%,#77b55a100%);background:-webkit-linear-gradient(top,#72b352 5%,#77b55a100%);background:-o-linear-gradient(top,#72b352 5%,#77b55a100%);background:-ms-linear-gradient(top,#72b352 5%,#77b55a100%);background:linear-gradient(to bottom,#72b352 5%,#77b55a100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=\'#72b352\',endColorstr=\'#77b55a\',GradientType=0);background-color:#72b352;}.greenbtn:active{position:relative;top:1px;}.bluebtn{-moz-box-shadow:inset 0 1px 0 0 #54a3f7;-webkit-box-shadow:inset 0 1px0 0 #54a3f7;box-shadow:inset 0 1px 0 0#54a3f7;background:-webkit-gradient(linear,left top,leftbottom,color-stop(0.05,#007dc1),color-stop(1,#0061a7));background:-moz-linear-gradient(top,#007dc1 5%,#0061a7100%);background:-webkit-linear-gradient(top,#007dc1 5%,#0061a7100%);background:-o-linear-gradient(top,#007dc1 5%,#0061a7100%);background:-ms-linear-gradient(top,#007dc1 5%,#0061a7100%);background:linear-gradient(to bottom,#007dc1 5%,#0061a7100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=\'#007dc1\',endColorstr=\'#0061a7\',GradientType=0);background-color:#007dc1;-moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;border:1px solid#124d77;display:inline-block;cursor:pointer;color:#fff !important;;font-family:arial;font-size:13px;padding:6px24px;text-decoration:none;text-shadow:0 1px 0#154682}.bluebtn:hover{background:-webkit-gradient(linear,left top,leftbottom,color-stop(0.05,#0061a7),color-stop(1,#007dc1));background:-moz-linear-gradient(top,#0061a7 5%,#007dc1100%);background:-webkit-linear-gradient(top,#0061a7 5%,#007dc1100%);background:-o-linear-gradient(top,#0061a7 5%,#007dc1100%);background:-ms-linear-gradient(top,#0061a7 5%,#007dc1100%);background:linear-gradient(to bottom,#0061a7 5%,#007dc1100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=\'#0061a7\',endColorstr=\'#007dc1\',GradientType=0);background-color:#0061a7;}.bluebtn:active{position:relative;top:1px;}.yellowbtn{-moz-box-shadow:inset 0 1px 0 0 #fff6af;-webkit-box-shadow:inset 01px 0 0 #fff6af;box-shadow:inset 0 1px 0 0#fff6af;background:-webkit-gradient(linear,left top,leftbottom,color-stop(0.05,#ffec64),color-stop(1,#ffab23));background:-moz-linear-gradient(top,#ffec64 5%,#ffab23100%);background:-webkit-linear-gradient(top,#ffec64 5%,#ffab23100%);background:-o-linear-gradient(top,#ffec64 5%,#ffab23100%);background:-ms-linear-gradient(top,#ffec64 5%,#ffab23100%);background:linear-gradient(to bottom,#ffec64 5%,#ffab23100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=\'#ffec64\',endColorstr=\'#ffab23\',GradientType=0);background-color:#ffec64;-moz-border-radius:6px;-webkit-border-radius:6px;border-radius:6px;border:1px solid#fa2;display:inline-block;cursor:pointer;color:#333 !important;;font-family:arial;font-size:15px;font-weight:bold;padding:6px24px;text-decoration:none;text-shadow:0 1px 0#fe6}.yellowbtn:hover{background:-webkit-gradient(linear,left top,leftbottom,color-stop(0.05,#ffab23),color-stop(1,#ffec64));background:-moz-linear-gradient(top,#ffab23 5%,#ffec64100%);background:-webkit-linear-gradient(top,#ffab23 5%,#ffec64100%);background:-o-linear-gradient(top,#ffab23 5%,#ffec64100%);background:-ms-linear-gradient(top,#ffab23 5%,#ffec64100%);background:linear-gradient(to bottom,#ffab23 5%,#ffec64100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=\'#ffab23\',endColorstr=\'#ffec64\',GradientType=0);background-color:#ffab23;}.yellowbtn:active{position:relative;top:1px;}3、所需素材下载。右键点击下面的素材图标保存到本地,然后再把图片上传到主题的img文件夹中,没有就自己新建一个文件夹。。
猜你可能想看的VPS
- R9Host→€2.99 月 512MB 内存 15GB NVMe 空间虚拟空间(主机)
- 搬瓦工 香港 pccw 机器 39.99 刀的已经下架 目前 79.99香港VPS[主机]
- js 获取当前时间方法全球[VPS测评]
- hkserversolution→台湾动态 VPS 随意切换 IP 7.全球[VPS测评]
- spinservers→美国服务器 30 分钟上机 超便宜+超高配+10美国VPS[主机]
- 干货推荐 新 老用户都可以买→腾讯云服务器(VPS) 包括“香港”等多香港VPS[主机]
- 劳动节 centerhop→新加坡 VPS $1.5 月 256M 内存全球[VPS测评]
- SSDNodes→新加坡 西雅图 洛杉矶 达拉斯 纽约 德国 加拿大等 全球[VPS测评]
- 便宜 VPS $20 年 512M 内存 10G SSD 1Gbps 不全球[VPS测评]
- 疯狂猜成语 图猜成语一个老人说了很多话旁边一个人在叹气是什么成语?全球[VPS测评]
- raksmart→美国(西海岸)独立服务器 优化线路 低至$46 月 高独立服务器[U]
- NecoVM 五一促销,国内联通 移动大带宽 NAT 最低 24 元 月全球[VPS测评]
- CentOS 系统安装 Transmission 和 FlexGet 全全球[VPS测评]
- Colohub→$7 月 1GB 内存 25GB SSD 空间 1TB 虚拟空间(主机)
- RAKsmart双十一活动 每天10台独服月付30刀秒杀,注册就送10刀全球[VPS测评]
- CloudSilk新上香港cmi vps,500Mbps大带宽,三网cm香港VPS[主机]
- 用XAMPP搭建本地PHP测试环境及安装WordPress全球[VPS测评]
- StockVPS 纽约机房 512m内存15g硬盘500g流量100m带全球[VPS测评]
- [双十一]hostetski.rue俄罗斯圣彼得堡 折扣高达 60!全球[VPS测评]
- 消费复苏形势良好,我们将多措并举实施扩大内需政策全球[VPS测评]
- 奇维云优惠活动:香港CN21核1G1M带宽云服务器免费领取香港VPS[主机]
- 2022年亚马逊Prime会员日将于7月12日和13日举行,覆盖24个站全球[VPS测评]
- 做跨境电商,如何打造私域流量?全球[VPS测评]
- 青云互联:香港CN2 GIA VPS,月付15.2起;日本CN2 VPS日本VPS[主机]
- 7月份,经济复苏边际趋缓,央行降息幅度先稳后升全球[VPS测评]
- 云群网络怎么样?香港云服务器高端弹性云2核2G2M带宽,仅588元/年香港VPS[主机]
- 硅云:香港免备案云服务器仅232元/年;香港2核2G2M仅482元/年香港VPS[主机]
- CombCloud,香港沙田CN2VPS测评,2核1G52元/月,安畅C香港VPS[主机]
- 香港云服务器怎么选?云服务器性能测评对比香港VPS[主机]
- 74块钱一年的云服务器可以用来做什么?全球[VPS测评]
转载请注明原文地址:http://140.238.13.167:12355/read-134877.html











