Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //(self-closing shortcodes )
- //1. besic shortcode test (self-closing shortcodes )
- function arnab( $atts ){
- return '<a href="http://www.google.com">google</a>';
- }
- add_shortcode( 'google', 'arnab' ); /*function name like arnab and
- shortcode name same hole hobena*/
- //ref: http://codex.wordpress.org/Shortcode_API
- //ref tuto - http://code.tutsplus.com/tutorials/wordpress-shortcodes-the-right-way--wp-17165
- // tow types of shortcode 1.self-closing shortcodes
- //2.Enclosing
- /*Usages */
- //[google]
- //2. shortcode with Attributes (self-closing shortcodes )
- function button_shortcode( $atts ) {
- extract( shortcode_atts( array(
- 'link' => 'http://google.com', //here link and text is Attributes
- 'text' => 'something else', //here http://google.com is default value
- ), $atts ) );
- return '<a style="background:red" href='.$link.'>'.$text.'</a>';
- }
- add_shortcode( 'botton', 'button_shortcode' );
- /*Usages */
- //[botton link="http://www.google.com text="botton""]
- //return korte hobe '' er bhitor and Attributes return hobe '..' er bhitor
- //3.shortcode with Attributes (self-closing shortcodes )youtube
- function youtube_shortcode( $atts ) {
- extract( shortcode_atts( array(
- 'width' => 'http://google.com',
- 'height' => 'something else',
- 'id' => 'something else',
- ), $atts ) );
- return '<iframe width="'.$width.'" height="'.$height.'" src="//www.youtube.com/embed/'.$id.'" frameborder="0" allowfullscreen></iframe>';
- }
- add_shortcode( 'youtube', 'youtube_shortcode' );
- /*Usages */
- //[youtube width="" height="" id=""]
- //( Enclosing shortcods)
- //1.besic Enclosing shortcods
- function besic_enclosing_shortcods( $atts, $content = null ) {
- return ''.$content.'';
- }
- add_shortcode( 'besic_enclosing_shortcods', 'besic_enclosing_shortcods' );
- /*Usages */
- //[besic_enclosing_shortcods]arnab[/besic_enclosing_shortcods]
- //2.with Attribute( Enclosing shortcods)
- function youtube_shortcode( $atts, $content = null ) {
- extract( shortcode_atts( array(
- 'width' => '560',
- 'height' => '315',
- ), $atts, 'youtube' ) );
- return '<iframe class="video_iframe" width="'.$width.'" height="'.$height.'" src="//www.youtube.com/embed/'.$content.'" frameborder="0" allowfullscreen></iframe>';
- }
- add_shortcode('youtube', 'youtube_shortcode');
- /*Usages */
- //[youtube width="426" height="251"]kc-R9OeyArg[/youtube]
- // This code will enable Shortcodes in WordPress Text Widget add this code to functions.php
- add_filter('widget_text', 'do_shortcode');
- // This code will enable Shortcodes in comment add this code to functions.php
- add_filter( 'comment_text', 'do_shortcode' );
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement