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');
[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]
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]
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://infolab.stanford.edu/pub/papers/google.pdf[/embedpdf]
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]
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]
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"]
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"]
Source: https://habr.com/ru/post/129998/
All Articles