Your SlideShare is downloading. ×
Using shortcode in plugin development
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Using shortcode in plugin development

277

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
277
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. USING SHORTCODEIN PLUGIN DEVELOPMENTGHANSHYAM KHANALPROUD MEMBER OF WORDPRESS NEPALNCOMSERVICES.COMIT-S, NEPAL
  • 2. SHORTCODE API• Introduced in WordPress 2.5• It’s a tag that can dynamically insert content into your wordpress site. 1. [mycode] 2. [mycode foo="bar" id="123" color="red" something="data"] 3. [mycode]Some Content[/mycode] 4. [mycode]<p><a href="http://example.com/">HTML Content</a></p>[/mycode] 5. [mycode]Content [another-shotcode] more content[/mycode] 6. [mycode foo="bar" id="123"]Some Content[/mycode]
  • 3. CREATING SHORTCODEadd_shortcode( $tag , $func );function wpnepal_shortcode ( ) { return "Hello WP Nepal Meetup!";}add_shortcode(wpnepal, wpnepal_shortcode);[wpnepal]
  • 4. CREATING SHORTCODE…function wpnepal_shortcode ( $atts, $content) { return "{$atts[greet]} WP Nepal Meetup! {$content}";}add_shortcode(wpnepal, wpnepal_shortcode);[wpnepal greet=“Hello”]Welcome[/wpnepal]
  • 5. A PROBLEMNeed to add excerpt of a post to anotherTHE SOLUTIONEmbed Post Pluginhttp://wordpress.org/extend/plugins/embed-post
  • 6. EMBED POSTfunction embed_post_shortcode( $atts ){ extract( shortcode_atts( array( post_id => 0, type => excerpt’ ), $atts ) ); global $post; [embed_post post_id=‘12’] $post = get_post($post_id); if($post->post_status == "publish"){ setup_postdata( $post ); $excerpt = <div class="embed_post">; $excerpt .= get_the_excerpt(); $excerpt .= </div>; wp_reset_query(); return $excerpt; }}add_shortcode(embed_post, embed_post_shortcode);
  • 7. MORE SHORTCODE• Run Shortcode anywhere in template files:do_shortcode([wpnepal]);• Run shortcode in a text widget:add_filter(widget_text, do_shortcode);
  • 8. THANK YOU QUESTIONS?

×