目前常用的社會化分享工具有 百度分享? 和 JiaThis,特別是這個JiaThis年代夠久遠,在百度也加入這個領域后,居然還堅持為大家提供免費工具,這里點32個贊!
隨著時代的變化,這些分享工具自帶的小圖標卻一成不變,已不符合目前流行的扁平化風格,與網站風格極不協調,但有些網站雖用的也上面兩款分享工具,但圖標卻不一樣,扁平、大方、簡潔,顯得高大上。今天就分享一下修改后的代碼,起個拋磚引玉的作用,以JiaThis分享工具為例,下面是修改后的效果:
基本原理就是找到默認分享代碼的DIV選擇器,然后隱藏背景圖片,添加字體圖標并重寫樣式。
一、首先將下面代碼添加到當前主題functions.php的最后:
- function?entry_share($content)?{
- if?(is_single())?{
- ????$content?.=?'
- ????<div?class="entry-share">
- ????????<div?class="share-box">
- ????????????<span?class="share-pu">分享到</span>
- ????????????<!--?JiaThis?Button?BEGIN?-->
- ????????????<div?class="jiathis_style_32x32">
- ????????????????<a?class="jiathis_button_tsina"><i?class="fa?fa-weibo"></i></a>
- ????????????????<a?class="jiathis_button_weixin"><i?class="fa?fa-wechat"></i></a>
- ????????????????<a?class="jiathis_button_renren"><i?class="fa?fa-renren"></i></a>
- ????????????????<a?class="jiathis_button_qzone"><i?class="fa?fa-qq"></i></a>
- ????????????????<a?class="jiathis_button_fb"><i?class="fa?fa-facebook"></i></a>
- ????????????????<a?class="jiathis_button_twitter"><i?class="fa?fa-twitter"></i></a>
- ????????????????<a?href="http://www.jiathis.com/share"?class="jiathis?jiathis_txt?jtico?jtico_jiathis"?target="_blank"><span><i?class="fa?fa-share-alt"></i></span></a>
- ????????????????<a?class="jiathis_counter_style"></a>
- ????????????</div>
- ????????</div>
- ????????<script?type="text/javascript"?src="http://v3.jiathis.com/code/jia.js"?charset="utf-8"></script>
- ????????<!--?JiaThis?Button?END?-->
- ????</div>';
- }
- return?$content;
- }
- add_filter('the_content','entry_share');
之后分享代碼會自動添加到文章正文的下面。
上面代碼只是在原JiaThis分享代碼基礎上添加了字體圖標。
二、再把下面配套的樣式添加到當前主題樣式文件style.css中即可。
展示代碼展開
- /**?外部盒子?**/
- .entry-share?{
- ????font-size:?14px;
- ????text-align:?center;
- ????margin:?0?auto?20px;
- }
- /*********?分享文字?********/
- .entry-share?.share-pu {
- ????font-weight:?700;
- ????line-height:?40px;
- }
- .entry-share?.share-pu?{
- ????float:?left;
- ????color:?#4d4d4d;
- }
- /********?分享樣式?********/
- .entry-share?div.share-box?{
- ????display:?inline-block;
- ????overflow:?hidden;
- }
- .entry-share?.jiathis_style_32x32?{
- ????float:?left?!important;
- ????margin-left:?10px;
- }
- .entry-share?.jiathis_style_32x32?a?{
- ????float:?left;
- ????width:?40px;
- ????height:?40px;
- ????color:?#a8a8a8;
- ????font-size:?16px?!important;
- ????display:?block;
- ????border-radius:?5px;
- ????margin-right:?10px;
- ????border:?1px?solid?#999;
- }
- .entry-share?.jiathis_style_32x32?a:hover?{
- ????text-decoration:?none;
- ????color:?#fff;
- }
- /**?圖標大小?**/
- .entry-share?.jiathis_style_32x32?a?span?{
- ????background:?transparent?!important;
- ????width:?38px?!important;
- ????height:?38px?!important;
- ????padding:?0?!important;
- ????margin:?0?!important;
- ????float:?none?!important;
- ????font-size:?20px?!important;
- ????display:?block?!important;
- ????text-align:?center?!important;
- ????line-height:?38px?!important;
- }
- /********?更多分享?********/
- .entry-share?.jiathis_style_32x32?a.jtico_jiathis?{
- ????background:?transparent?!important;
- ????width:?38px?!important;
- ????height:?38px?!important;
- ????padding:?0?!important;
- ????margin:?0?!important;
- ????font-size:?24px?!important;
- ????display:?block?!important;
- ????text-align:?center?!important;
- ????line-height:?38px?!important;
- }
- .entry-share?.jiathis_style_32x32?a:hover.jtico_jiathis?{
- ????background:?#666?!important;
- ????border-color:?#666;
- }
- /********?分享次數?********/
- .entry-share?.jiathis_style_32x32?a.jiathis_counter_style?{
- ????width:?auto;
- ????margin-left:?10px;
- ????padding:?0?15px;
- ????border-radius:?5px;
- ????display:?inline-block;
- ????position:?relative;
- ????background:?#e8e8e8;
- ????border-color:?#e8e8e8;
- ????color:?#fff?!important;
- }
- /**?箭頭?**/
- .entry-share?.jiathis_style_32x32?a.jiathis_counter_style:before?{
- ????content:?'';
- ????width:?0;
- ????height:?0;
- ????border-style:?solid;
- ????border-width:?10px?10px?10px?0;
- ????border-color:?transparent?#e8e8e8?transparent?transparent;
- ????position:?absolute;
- ????right:?100%;
- ????top:?50%;
- ????margin-top:?-10px;
- }
- .entry-share?.jiathis_style_32x32?a.jiathis_counter_style?span.jiathis_bubble_style?{
- ????color:?#666?!important;
- ????font-size:?14px?!important;
- ????width:?auto?!important;
- }
- /********?不同圖標懸停背景顏色?********/
- .entry-share?.jiathis_style_32x32?a:hover.jiathis_button_tsina?{
- ????background:?#e74c3c;
- ????border-color:?#e74c3c;
- }
- .entry-share?.jiathis_style_32x32?a:hover.jiathis_button_weixin?{
- ????background:?#2ecc71;
- ????border-color:?#2ecc71;
- }
- .entry-share?.jiathis_style_32x32?a:hover.jiathis_button_fb?{
- ????background:?#4760A5;
- ????border-color:?#4760A5;
- }
- .entry-share?.jiathis_style_32x32?a:hover.jiathis_button_twitter?{
- ????background:?#50ABF1;
- ????border-color:?#50ABF1;
- }
- .entry-share?.jiathis_style_32x32?a:hover.jiathis_button_renren?{
- ????background:?#3777BE;
- ????border-color:?#3777BE;
- }
- .entry-share?.jiathis_style_32x32?a:hover.jiathis_button_qzone?{
- ????background:?#2174C3;
- ????border-color:?#2174C3;
- }
鼠標懸停在分享按鈕上,背景會變成不同的顏色。
如果你動手能力比較強,也可以同樣替換百度分享圖標。
繼續閱讀

關于本站
分享交流WordPress經驗與技巧,關注前端設計與網站制作。僅用于功能演示。
2017年5月11日 22點24分 1F
站點一直是二維碼分享,所以沒有使用這類分享
2017年5月11日 22點46分 2F
暫時都沒有用。
2017年5月12日 14點08分 3F
相信鳥哥是最棒的。
2017年5月12日 18點29分 B1
@ Win7en樂園 這次不給力了啊 竟然晚了這么久 板凳都沒搶到
2017年5月17日 07點09分 B2
@ 雅兮網 意外,意外了
2017年5月12日 21點38分 4F
百度的剛開始看著很丑,但看多了,其實也還好…
2017年5月14日 14點09分 5F
有沒有https的
2017年5月15日 09點49分 6F
這個方法不錯,一通百通,這樣一來就可以折騰適合自己站點的分享圖標了
2017年5月15日 14點29分 7F
鳥哥的分享已經換了…
2017年5月15日 16點03分 8F
呀,鼠標滑過時的背景都不一樣 …
2017年5月15日 18點47分 9F
不錯啊
2017年5月16日 11點30分 10F
不錯不錯,支持鳥哥
2017年5月16日 15點23分 11F
分享文章到社交網站怎么把文章的圖片也分享出去呀
2017年5月17日 11點15分 B1
@ OEASY 新浪微博就可以選擇圖片,其它的貌似沒有,應該和社交網站有關吧
比如我這篇文章,可以試試
2017年5月17日 14點36分 12F
人人網和騰訊微博現在基本都掛了,分享功能首行圖標中應該把它倆撤了。
2017年5月19日 16點16分 13F
這種效果我找很久了,需要用到灰色的,我已經替換大家可以來看看
2017年5月22日 22點29分 14F
不錯
2017年6月8日 16點21分 15F
技術帖子,我的最愛
2017年8月9日 21點23分 16F
這是我找到的教程中最最好用的分享插件設置教程,滿足了我的需求,非常感謝!下一步就是看看贊和打賞功能,謝謝!
2017年11月18日 21點13分 17F
為什么我的顯示是豎著的 你這個顯示是橫著的呢??
2017年12月29日 14點49分 18F
share我們都喜歡,可惜好難
2018年10月4日 08點34分 19F
現在很少有人分享了
2018年10月24日 19點08分 20F
這個功能還是不錯的
