اشتراک گذاری نوشته ها در وردپرس بدون افزونه
برای به اشتراک گذاری نوشته ها در وردپرس، افزونه های مختلفی مانند Social Sharing Plugin و AddToAny Share Buttons وجود دارند ولی اگر تمایلی به استفاده از افزونه ندارید یا به دلیل محدودیت ها؛ قادر به استفاده از آنها نیستید میتوانید این کار را بدون استفاده از افزونه انجام دهید. برای این منظور همراه ما باشید.
لیست 10 افزونه برتر اشتراک گذاری محتوا در وردپرس
روش کار در دو مرحله می باشد :
- اضافه کردن کدها در function.php
- اضافه کردن کدهای css
کدهای زیر را باید در فایل function.php قرار دهید:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
// تابع در خواست عکس کوچک function get_the_post_thumbnail_src($img) { return (preg_match('~\bsrc="([^"]++)"~', $img, $matches)) ? $matches[1] : ''; } function roka_social_buttons($content) { global $post; if(is_singular() || is_home()){ // دریافت آدرس صفحه فعلی $sb_url = urlencode(get_permalink()); // دریافت عنوان صفحه فعلی $sb_title = str_replace( ' ', '%20', get_the_title()); // دریافت تصویر کوچک برای پینترست $sb_thumb = get_the_post_thumbnail_src(get_the_post_thumbnail()); // ساخت آدرس اشتراک گذاری بدون استفاده از اسکریپت $twitterURL = 'https://twitter.com/intent/tweet?text='.$sb_title.'&url='.$sb_url.'&via=wpvkp'; $facebookURL = 'https://www.facebook.com/sharer/sharer.php?u='.$sb_url; $bufferURL = 'https://bufferapp.com/add?url='.$sb_url.'&text='.$sb_title; $whatsappURL = 'whatsapp://send?text='.$sb_title . ' ' . $sb_url; $linkedInURL = 'https://www.linkedin.com/shareArticle?mini=true&url='.$sb_url.'&title='.$sb_title; if(!empty($sb_thumb)) { $pinterestURL = 'https://pinterest.com/pin/create/button/?url='.$sb_url.'&media='.$sb_thumb[0].'&description='.$sb_title; } else { $pinterestURL = 'https://pinterest.com/pin/create/button/?url='.$sb_url.'&description='.$sb_title; } // Pinterest $pinterestURL = 'https://pinterest.com/pin/create/button/?url='.$sb_url.'&media='.$sb_thumb[0].'&description='.$sb_title; $gplusURL ='https://plus.google.com/share?url='.$sb_title.''; // اضافه شدن دکمه اشتراک گذاری را در انتهای صفحه یا محتوای صفحه $content .= '<div class="social-box"><div class="social-btn">'; $content .= '<a class="col-1 sbtn s-twitter" href="'. $twitterURL .'" target="_blank" rel="nofollow"><span>Share on twitter</span></a>'; $content .= '<a class="col-1 sbtn s-facebook" href="'.$facebookURL.'" target="_blank" rel="nofollow"><span>Share on facebook</span></a>'; $content .= '<a class="col-2 sbtn s-whatsapp" href="'.$whatsappURL.'" target="_blank" rel="nofollow"><span>WhatsApp</span></a>'; $content .= '<a class="col-2 sbtn s-pinterest" href="'.$pinterestURL.'" data-pin-custom="true" target="_blank" rel="nofollow"><span>Pin It</span></a>'; $content .= '<a class="col-2 sbtn s-linkedin" href="'.$linkedInURL.'" target="_blank" rel="nofollow"><span>LinkedIn</span></a>'; $content .= '<a class="col-2 sbtn s-buffer" href="'.$bufferURL.'" target="_blank" rel="nofollow"><span>Buffer</span></a>'; $content .= '</div></div>'; return $content; }else{ // اگر پست / صفحه نیست ، دکمه اشتراک گذاری را در آن قرار ندهید return $content; } }; // اگر می خواهید دکمه های اجتماعی را در زیر پست خود به صورت خودکار نشان دهید ، the_content را فعال کنید. add_filter( 'the_content', 'roka_social_buttons'); // این یک کد کوتاه یک شورتکد [social] ایجاد می کند. add_shortcode('social','roka_social_buttons'); |
بعد از اضافه کردن این کدها میتوانید نتیجه را در نوشته ها مشاهده نمایید:
2- اضافه کردن کدهای css
برای تغییر استایل آن می توانید از این کدهای زیر استفاده نمایید: (باید از قبل فونت awesome را به قالب خود اضافه کرده باشید)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
.social-box { display: block; margin: -20px 0 40px; padding: 0 6rem 0; } .social-box:last-of-type { margin: 0 0 40px; } .social-btn { display: block; width: 100%; } a.col-2.sbtn span { display: none; } a.col-1.sbtn { width: 180px; display: inline-block; text-align: center; border-radius: 50px; padding: 10px; color: #fff; margin: 0 0.5% 0 0; font-size: 15px; } a.col-1.sbtn span { margin: 0 0 0 15px; } a.col-2.sbtn { width: 6%; display: inline-block; text-align: center; border-radius: 50px; padding: 10px; color: #fff; margin: 0 0.5% 0 0; line-height: 1.825 !important; max-width: 50px; min-width: 50px; } .s-twitter { background: #03A9F4; } .s-twitter::before { font-family: fontawesome; content: '\f099'; } .s-twitter:hover { background: #0093d6; } .s-facebook { background: #3F51B5; } .s-facebook::before { font-family: fontawesome; content: '\f09a'; } a.col-1.sbtn.s-facebook:hover { background: #2f409f; } .s-googleplus { background: #F44336; } .s-googleplus::before { font-family: fontawesome; content: '\f0d5'; } .s-googleplus:hover { background: #c82c21; } .s-whatsapp { background: #4CAF50; } .s-whatsapp::before { font-family: fontawesome; content: '\f232'; } a.col-2.sbtn.s-whatsapp:hover { background: #3d9440; } .s-linkedin { background: #1a7baa; } .s-linkedin::before { font-family: fontawesome; content: '\f0e1'; } a.col-2.sbtn.s-linkedin:hover { background: #136288; } .s-pinterest { background: #bd081c; } .s-pinterest::before { font-family: fontawesome; content: '\f231'; } a.col-2.sbtn.s-pinterest:hover { background: #a10718; } .s-buffer { background: #ced7df; } .s-buffer::before { font-family: fontawesome; content: '\e804'; } a.col-2.sbtn.s-buffer:hover { background: #c3c5c8; } /******************************** ////// Important *******************************/ .social-btn a:last-of-type { margin: 0; } @media only screen and (max-width: 1200px) { a.col-1.sbtn { width: 180px; display: inline-block; text-align: center; border-radius: 50px; padding: 10px; color: #fff; margin: 0 0.5% 0 0; font-size: 15px; } } @media only screen and (max-width: 768px) { a.col-1.sbtn { width: 46px; } a.col-1.sbtn span { display: none; } } |