Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*--To use wordpress shortcode, you have to use the following code in function.php--*/
- /*=========================================================================
- add this line for instance into functions.php of your theme to add shortcode in text widgets
- ==========================================================================*/
- add_filter('widget_text', 'do_shortcode');
- /*=========================================================================
- simple shortcode for youtube video
- ==========================================================================*/
- function youtube_video_shortcode( $atts, $content = null ) {
- return '<iframe width="640" height="360" src="//www.youtube.com/embed/'.$content.'" frameborder="0" allowfullscreen></iframe>';
- }
- add_shortcode( 'youtube', 'youtube_video_shortcode' );
- //Usage of the shortcode
- [youtube]c8Lq6wHSEA8[youtube]
- /*=========================================================================
- simple shortcode with attribute for vimeo video
- ==========================================================================*/
- function vimeo_video_shortcode( $atts, $content = null ) {
- extract(shortcode_atts(array(
- 'width' =>'500',
- 'height' => '281',
- 'userid' => 'sayfulislam',
- 'username' => 'sayful islam',
- 'videoid' => '82750579'
- ), $atts));
- return '<iframe src="//player.vimeo.com/video/'.$videoid.'" width="'.$width.'" height="'.$height.'" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> <p><a href="http://vimeo.com/'.$videoid.'">Roka Puta 60 Seconds</a> from <a href="http://vimeo.com/'.$userid.'">'.$username.'</a> on <a href="https://vimeo.com">Vimeo</a>.</p>';
- }
- add_shortcode( 'vimeo', 'vimeo_video_shortcode' );
- //Usage of the shortcode
- [vimeo width='640' height='360' userid='sayfulislam' username='sayful islam' videoid='82750579']
- /*=========================================================================
- simple shortcode in shortcode with attribute for slider images
- ==========================================================================*/
- function slider_wrapper_shortcode( $atts, $content = null ) {
- extract(shortcode_atts(array(
- 'type' =>'',
- ), $atts));
- return '<div id="slides">'.do_shortcode($content).'</div>';
- }
- add_shortcode( 'slider', 'slider_wrapper_shortcode' );
- function slide_shortcode( $atts, $content = null ) {
- extract(shortcode_atts(array(
- 'src' =>'',
- 'alt' =>'',
- ), $atts));
- return '<img src="'.$src.'" alt="'.$alt.'" />';
- }
- add_shortcode( 'slides', 'slide_shortcode' );
- //Usage of shortcode
- [slider][slides src="http://localhost/andia/wp-content/themes/andia-agency/assets/img/slider/1.jpg"][slides src="http://localhost/andia/wp-content/themes/andia-agency/assets/img/slider/2.jpg"][slides src="http://localhost/andia/wp-content/themes/andia-agency/assets/img/slider/3.jpg"][slides src="http://localhost/andia/wp-content/themes/andia-agency/assets/img/slider/4.jpg"][/slider]
- //using shortcode directly to your theme
- <?php echo do_shortcode('[slider]'); ?>
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement