Advertisement
arnabkumar

short_code_note

Mar 28th, 2014
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.83 KB | None | 0 0
  1. <?php    
  2.  
  3.                            //(self-closing shortcodes )
  4. //1. besic shortcode test (self-closing shortcodes )
  5. function arnab( $atts ){
  6.     return '<a href="http://www.google.com">google</a>';
  7. }
  8. add_shortcode( 'google', 'arnab' ); /*function name like arnab and
  9.                                       shortcode name same hole hobena*/
  10.  
  11. //ref: http://codex.wordpress.org/Shortcode_API
  12. //ref tuto - http://code.tutsplus.com/tutorials/wordpress-shortcodes-the-right-way--wp-17165
  13.  
  14. // tow types of shortcode 1.self-closing shortcodes
  15.                           //2.Enclosing
  16.  
  17.  
  18. /*Usages */
  19. //[google]
  20.  
  21.  
  22.  
  23.  
  24.  
  25. //2. shortcode with Attributes (self-closing shortcodes )
  26. function button_shortcode( $atts ) {
  27.     extract( shortcode_atts( array(
  28.         'link' => 'http://google.com', //here link and text is Attributes
  29.         'text' => 'something else',    //here http://google.com is default value
  30.     ), $atts ) );
  31.  
  32.     return '<a style="background:red" href='.$link.'>'.$text.'</a>';
  33. }
  34. add_shortcode( 'botton', 'button_shortcode' );
  35.  
  36.  
  37. /*Usages */
  38. //[botton link="http://www.google.com text="botton""]
  39.  
  40.  
  41. //return korte hobe '' er bhitor and Attributes return hobe '..' er bhitor
  42.  
  43. //3.shortcode with Attributes (self-closing shortcodes )youtube
  44. function youtube_shortcode( $atts ) {
  45.     extract( shortcode_atts( array(
  46.         'width' => 'http://google.com',
  47.         'height' => 'something else',
  48.         'id' => 'something else',
  49.     ), $atts ) );
  50.  
  51.     return '<iframe width="'.$width.'" height="'.$height.'" src="//www.youtube.com/embed/'.$id.'" frameborder="0" allowfullscreen></iframe>';
  52. }
  53. add_shortcode( 'youtube', 'youtube_shortcode' );
  54.  
  55. /*Usages */
  56. //[youtube width="" height="" id=""]
  57.  
  58.  
  59.  
  60.                       //( Enclosing shortcods)
  61.                                    
  62. //1.besic Enclosing shortcods
  63. function besic_enclosing_shortcods( $atts, $content = null ) {
  64.     return ''.$content.'';
  65. }
  66. add_shortcode( 'besic_enclosing_shortcods', 'besic_enclosing_shortcods' );
  67.  
  68. /*Usages */
  69. //[besic_enclosing_shortcods]arnab[/besic_enclosing_shortcods]
  70.  
  71.  
  72.  
  73. //2.with Attribute( Enclosing shortcods)
  74.  
  75.  
  76. function youtube_shortcode( $atts, $content = null  ) {
  77.  
  78.     extract( shortcode_atts( array(
  79.         'width' => '560',
  80.         'height' => '315',
  81.     ), $atts, 'youtube' ) );
  82.  
  83.     return '<iframe class="video_iframe" width="'.$width.'" height="'.$height.'" src="//www.youtube.com/embed/'.$content.'" frameborder="0" allowfullscreen></iframe>';
  84. }  
  85. add_shortcode('youtube', 'youtube_shortcode');
  86.  
  87. /*Usages */
  88. //[youtube width="426" height="251"]kc-R9OeyArg[/youtube]
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111. // This code will enable  Shortcodes in WordPress Text Widget add this code to functions.php
  112. add_filter('widget_text', 'do_shortcode');
  113.  
  114.  
  115. // This code will enable  Shortcodes in comment add this code to functions.php
  116. add_filter( 'comment_text', 'do_shortcode' );
  117.  
  118. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement