शॉर्टकोड कस्टम फीचर्स हैं जो वर्डप्रेस में पोस्ट लिखते समय समय की बचत करते हैं। आज मैं आपको 10 सबसे अधिक इस्तेमाल किए जाने वाले वर्डप्रेस शॉर्टकोड से परिचित कराना चाहता हूं।
किसी भी साइट का स्क्रीनशॉट दिखाएं
क्या आप किसी साइट का स्क्रीनशॉट लेना चाहते हैं और उसे अपनी साइट पर प्रदर्शित करना चाहते हैं? यह शांत शोर्ट आपको इसमें मदद करेगा। इस कोड को functions.php फाइल में कॉपी करें:
function wpr_snap( $atts, $content = null ) { extract(shortcode_atts(array( 'snap' => 'http://s.wordpress.com/mshots/v1/', 'url' => 'http://www.habrahabr.ru/', 'alt' => '', 'w' => '400', 'h' => '300' ), $atts)); $img = '<img src="' . $snap . '' . urlencode($url) . '?w=' . $w . '&h=' . $h . '" alt="' . $alt . '"/>'; return $img; } add_shortcode('snap', 'wpr_snap');
वह सब है। अब, Habr का स्क्रीनशॉट देखने के लिए, निम्न सामग्री के साथ एक पोस्ट जोड़ें:
[snap url="http://www.habrahabr.ru/" alt="" w="400" h="300"]
पेपैल दान लिंक जोड़ें
कई ब्लॉगर अपने ब्लॉग पर एक समान लिंक पोस्ट करते हैं और पाठकों से उनकी आर्थिक मदद करने के लिए कहते हैं। यदि, फिर भी, पेपाल रूस के लिए धन की स्वीकृति को सक्षम करता है, तो आप इस शॉर्टकट को अपने कार्यों में जोड़ सकते हैं।
function cwc_donate_shortcode( $atts ) { extract(shortcode_atts(array( 'text' => ' ?', 'account' => 'REPLACE ME', 'for' => 'Habr', ), $atts)); global $post; if (!$for) $for = str_replace(" ","+",$post->post_title); return '<a class="donateLink" href="https://www.paypal.com/cgi-bin/webscr?cmd=cxlick&business='.$account.'&item_name=+'.$for.'"> '.$text.' </a>'; } add_shortcode('donate', 'cwc_donate_shortcode');
और सही जगह पर
[donate]
क्लिक करने योग्य दृश्य के लिए एक ईमेल पता लाओ
किसी भी WordPress ब्लॉग, ज़ाहिर है, स्पैम है। यदि आप उपयोगकर्ताओं के ईमेल पते या अपनी साइट पर अपना पसंदीदा मेल प्रदर्शित करते हैं, तो आप मेल को इकट्ठा करने में स्पैमर्स के जीवन को जटिल बना सकते हैं। बस इस कोड को functions.php में जोड़ें:
function cwc_mail_shortcode( $atts , $content=null ) { for ($i = 0; $i < strlen($content); $i++) $encodedmail .= "&#" . ord($content[$i]) . ';'; return '<a href="mailto:'.$encodedmail.'">'.$encodedmail.'</a>'; } add_shortcode('mailto', 'cwc_mail_shortcode');
और आपको अफ्रीकी अरबपतियों के डेटाबेस में अपने साबुन के बारे में चिंता करने की ज़रूरत नहीं है, जो आपके पास मौजूद हर चीज से वंचित हैं। बस टैग में साबुन लपेटो
[mailto]email@yourdomain.ru[/mailto]
निजी सामग्री बनाएँ
मैं हमेशा साइट से सामग्री को कॉपी-पेस्ट नहीं करना चाहता हूं। आप केवल पंजीकृत कुछ निश्चित सामग्री दिखा सकते हैं। इसे फंक्शन्स में जोड़ें।
function cwc_member_check_shortcode( $atts, $content = null ) { if ( is_user_logged_in() && !is_null( $content ) && !is_feed() ) return $content; return ''; } add_shortcode( 'member', 'cwc_member_check_shortcode' );
और टैग में सामग्री लपेटें
[member] -.[/member]
फ्रेम में पीडीएफ दिखाएं
किसी साइट पर एक पीडीएफ फाइल की सामग्री को प्रदर्शित करने का एक अच्छा तरीका है। Google डॉक्स बचाव के लिए आते हैं। Functions.php में एक नया फ़ंक्शन जोड़ें:
function cwc_viewpdf($attr, $url) { return '<iframe src="http://docs.google.com/viewer?url=' . $url . '&embedded=true" style="width:' .$attr['width']. '; height:' .$attr['height']. ';" frameborder="0"> </iframe>'; } add_shortcode('embedpdf', 'cwc_viewpdf');
और पीडीएफ डालने की सामग्री में हम इस टैग का उपयोग करते हैं:
[embedpdf width="600px" height="500px"]http:
"केवल फ़ीड" सामग्री
यह शॉर्टकट केवल RSS ग्राहकों को कुछ सामग्री दिखाने की अनुमति देता है। और फिर, फ़ंक्शन को फ़ंक्शन में जोड़ें ।php:
function cwc_feedonly_shortcode( $atts, $content = null) { if (!is_feed()) return ""; return $content; } add_shortcode('feedonly', 'cwc_feedonly_shortcode');
और हम उस सामग्री को लपेटते हैं जो हम टैग में ग्राहकों को दिखाना चाहते हैं
[feedonly] -, .[/feedonly]
लिंक "उत्तर"
बहुत से लोग जानते हैं कि ट्विटर एक ब्लॉग के लिए एक यातायात जनरेटर है। और रीट्वीट साइट को ट्रैफ़िक बढ़ाते हैं।
function tweetmeme(){ return '<div class="tweetmeme"> <script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script> </div>'; } add_shortcode('retweet', 'tweetmeme');
और सही जगह पर
[retweet]
संलग्न छवियों को एक पोस्ट में दिखाएं
यह लघु पोस्ट से जुड़ी अंतिम छवि दिखा सकता है। इस शॉर्टकट को functions.php में जोड़ें:
function cwc_postimage($atts, $content = null) { extract(shortcode_atts(array( "size" => 'thumbnail', "float" => 'none' ), $atts)); $images =& get_children('post_type=attachment&post_mime_type=image&post_parent=' . get_the_id() ); foreach( $images as $imageID => $imagePost ) { $fullimage = wp_get_attachment_image($imageID, $size, false); $imagedata = wp_get_attachment_image_src($imageID, $size, false); $width = ($imagedata[1]+2); $height = ($imagedata[2]+2); return '<div class="postimage" style="width: '.$width.'px; height: '.$height.'px; float: '.$float.';"> '.$fullimage.' </div>'; } } add_shortcode("postimage", "cwc_postimage");
और पोस्ट में हम टैग जोड़ते हैं
[postimage]
Youtube वीडियो
यदि आप अपने ब्लॉग पर Youtube से एक वीडियो पोस्ट करना चाहते हैं, तो function.php में एक फ़ंक्शन जोड़ें:
function cwc_youtube($atts) { extract(shortcode_atts(array( "value" => '', "width" => '475', "height" => '350', "name"=> 'movie', "allowFullScreen" => 'true', "allowScriptAccess"=>'always', ), $atts)); return '<object style="height: '.$height.'px; width: '.$width.'px"> <param name="'.$name.'" value="'.$value.'"> <param name="allowFullScreen" value="'.$allowFullScreen.'"> <param name="allowScriptAccess" value="'.$allowScriptAccess.'"> <embed src="'.$value.'" type="application/x-shockwave-flash" allowfullscreen="'.$allowFullScreen.'" allowScriptAccess="'.$allowScriptAccess.'" width="'.$width.'" height="'.$height.'"> </embed> </object>'; } add_shortcode("youtube", "cwc_youtube");
और पोस्ट में आप टैग का उपयोग कर सकते हैं
[youtube value="http://www.youtube.com/watch?v=1aBSPn2P9bg"]
RSS ने खिलाया
और अंत में, आप फ़ंक्शन का उपयोग करके एक पोस्ट में एक मनमाना आरएसएस फ़ीड दिखा सकते हैं
include_once(ABSPATH.WPINC.'/rss.php'); function cwc_readRss($atts) { extract(shortcode_atts(array( "feed" => '', "num" => '1', ), $atts)); return wp_rss($feed, $num); } add_shortcode('rss', 'cwc_readRss');
और टैग
[rss feed="http://feeds.feedburner.com/catswhocode" num="5"]
मूल: css.dzone.com