WordPress文章内容添加彩色美化提示框代码教程 WordPress 第1张

有时候,WordPress的文章编辑器并不能满足我们的要求,那就要靠我们自己动手实现了。

将下列代码放在你主题目录的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');
/*彩色文本框 结束*/
/*添加文本编辑自定义快捷标签按钮 开始*/
 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', "" );
 function bolo_QTnextpage_arg1() {
 }
 </script>
 <?php
 }
 /*添加文本编辑自定义快捷标签按钮 结束*/

将下列代码放在你主题目录的style.css

因每个主题都不一样,建议还是直接在后台的外观自定义添加额外CSS

/*彩色代码框样式开始*/
#sc_notice {
 color: #7da33c;
 background: #ecf2d6 url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAaCAIAAAAmKNuZAAABXklEQVR42u2U2UrDQBSG+8K+heKC653bE/Ra9EZb04CmooI32aABk2C1bRprFibbxB/HNqUpJIHoVeEPzHLmyzlnzpxG826tRjXwXYvrtWiFy3TfO361BJcMExpDbjDSra7QO6mMa0lbxviR0iRNU5pSEn1BGLCpOX6CQVlcS9q0XA0nSeRI/UtO2WPrt8oupiScYMv2jba8XQqnWw848OmbnLKfdwF029NhYNrPxTjki0XXWcZiwhbzsaudFeCQe9jJ/auloBej2VEPMBDfLmCGOApwDhnAu1m+5sUQ2pDHuC3v4KK8wCrARQkJImfmizANh7HeJ+KNuMFW/NAGsQLOIR9h7IGYZzFcnIQVguXVQy8Y4Qd5FgsWhV3qKlBfbMqrR0jQAqvCVeQLBdW7wOKyQjn/3zKu/5FlLYC9eZr8toBpR6jWAubziI6E6wMINeGSwU+DOl019z/D1ahv/4DCs72FOK8AAAAASUVORK5CYII=') -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('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAaCAIAAAAmKNuZAAAA6UlEQVRIx+2UvQ6CMBSFmUicTFx8AV2Q5+DxgAES30J3HVzZjYAS3BnKgCTWAMfcjZRGftLEhZNvIWm/pNzTallgKUTLAguRpoRZ1yI1wGzwEM2b4Df6TI3xulhH7gE1JKmR7xEvButiHeUJv1OeadkgXe6Lm5lNCMm9AbrnDqjEnY8VIaaixT065kiOdl8S3TCnT8fDEToe9ukaPkLX8Em6ZE1IOlNMOmx5Ibp5XyeNgj/wSWSjcHuLYkqKkm6QbmVFMSfVuDigOHZq7P/lkil+AtoXjrngEZoP6hfNkbnC/5ofd6U6hXwBuEe/1fg+Wb0AAAAASUVORK5CYII=') -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('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAaCAIAAAAmKNuZAAABP0lEQVR42u2UzWrCQBSFfVoX/oDGB1DRF1GCOxHX/ruuaRY1GxUqVO0koAZLTGIy6ZGU0VLsjDDtSjgJTGbmm7n33NyE1W5LVALPUzIpRQ/cRS/F4nunc1yv6ekEHTcb0u1OS6W7cVo6bQ4GNAyjKMLb3+2geBhRao5GWCCKm6RStmFgo7/fL1VVz+fj78+5HIbedoupw3yuZTJCONLvY8PHYqErys8rgH6YzbDAGo/5OOQrjk4vFG7lCFPnO1JqVCocHHKPk5eNxu8mvtbrWEZ6PQ7OWa1wLMvXLWnZLIJwCeHgAsfxbZulCf4iR0xvrRZb6VoWiHfgYKU5HH7DNZvXuNDzZAaLwhazQlU5VtRqQlYIFYqifBVKtfq/ZSz/J2MtAOFIaAHXeURHgn00CELXhennBlUuP5r7n+Ek6hNJm/hQEU50HAAAAABJRU5ErkJggg==') -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('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAaCAAAAACMIRMSAAAAkUlEQVQoz73SQQuCQBCGYf//X3Jd7NCh0qgUiigTEiRbKCjRWJa3e80c67s+l/lmJsrURFms5Ne088dEoQMMhUxp0cNVInsfyr1/CGQ6oLaJQCeAzfcYdWhzB16YsIdQrZ+N0Gs1AmM5kSrbKgA3qbJp8haYCbTExXN3NgJd+lRZb/qaapvf5upRFv9+gA9S8wZGXgP/uZcaJgAAAABJRU5ErkJggg==') -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('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAaCAIAAAAmKNuZAAAACXBIWXMAAAsTAAALEwEAmpwYAAAABGdBTUEAALGOfPtRkwAAACBjSFJNAAB6JQAAgIMAAPn/AACA6QAAdTAAAOpgAAA6mAAAF2+SX8VGAAACgUlEQVR42mKMmPz0689/DNQA3OxMAAHE8un73x+//1PFuL///gMEEBMzEyMDlQDQKIAAYmKgKgAIICobBxBAVDYOIIBYyNDz/z/Drz////7/z8bMyMKMEvQAAcRCnlnhlnzMTAwHr3979v4PGwvCRIAAIs24f/8Zvv36F23Fn+smCORGWPBN2/N+z5Wv8OQBEEBEGfcfnKZ+/v7PwsTob8yb4yoAFHz6/s+03e9vPv/Fysz07z805QIEEAuhlAnyGpAhKcBiqMjhrMVlqcoJkVp3+vO2i18EuJhBwQfLBwABhNM4oCm///4X5GY2VeKw1eCy0+AE6oTLvvv6b/+1r3wcIF/++4fIVAABxILLd1rSbCZKnK463AqirJgKtp7/AowEYCZFEwcIICzGAR0FdJqHHk+gKS+uvLnv6ldWZiy5EyCAWDBC6p8wD4ujFpeeHAeucNhy/sudl79YWbAYBxBALMgJSoCLycuQL9iUV5gHFEwfv/1lYGTkYmMERigjWO/5hz/WnPx84s53kAg2mwACiAVuFlDeWJHdUZPrybvf609/vv7s552Xv4Hi3ByMcTYC+vLsvdvenb//4/uvfxxsTEw4MidAACFcBwyLR2/+1K158+Ljn28//wGjnxUck68+MSw//omBge/Npz8///wHmYW7SAMIIKhxQKf9+vv/5otfQJVA5TwcTEhlLMOD1783n/tirsIJjEpg6v30/R8uEwECCOE6RrADsSpiY2a48/Ln7Rc/OVgZf4HCE6frAAKI2Ez25y+I8fUnMIwZ8BTfAAFEbBHASFwVABBAVC4+AQKIysYBBBDT33//qWUW0CiAAGLh42QGllfUqrYBAgwAUQrczQJMgSUAAAAASUVORK5CYII=') -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;
}

上传图标文件到你的网站,把快捷标签左上角的图片上传到你的网站,并复制链接。

图片链接替换url('图标地址')里边的链接就可以了

使用方法

经典编辑器中可视化切换成文本,选择标签按钮。

WordPress文章内容添加彩色美化提示框代码教程 WordPress 第2张

发表评论

后才能评论