Mastering the shortcode api
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Mastering the shortcode api

on

  • 2,435 views

This presentation walks you through how to create and use custom shortcodes throughout your WordPress website, adding in anything from a simple header to an advanced nested layout.

This presentation walks you through how to create and use custom shortcodes throughout your WordPress website, adding in anything from a simple header to an advanced nested layout.

Statistics

Views

Total Views
2,435
Views on SlideShare
2,434
Embed Views
1

Actions

Likes
0
Downloads
12
Comments
0

1 Embed 1

http://www.php-talks.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Mastering the shortcode api Presentation Transcript

  • 1. Mastering the Shortcode API Peter Baylies Semper Fi Web DesignMonday, November 7, 11
  • 2. What’s a shortcode • It’s a tag that can dynamically insert content into your wordpress site. It should look sort of like this: [gallery]Monday, November 7, 11
  • 3. How do I make them? • with the add_shortcode() function • arguments: your shortcode’s name and your PHP function that it calls: add_shortcode(‘tag’,‘my_function_name’);Monday, November 7, 11
  • 4. Wait, my PHP function? • Yes, it can be passed up to three arguments: my_function_name($atts,$content,$code); • arguments passed to your shortcode • content contained within your shortcode • the name of the shortcode itselfMonday, November 7, 11
  • 5. Attributes • Shortcode attributes look like this: [gallery id=”123” columns=”4”] • They get processed with shortcode_atts() extract ( shortcode_atts ( array ( ‘id’ => null, ‘columns’=>3 ), $atts ) ); • This sets defaults and validates arguments.Monday, November 7, 11
  • 6. Content • Shortcodes can enclose content too. [caption]This is a caption.[/caption] The text in between the shortcode tags gets passed to $content for processing.Monday, November 7, 11
  • 7. Code • The name of the shortcode called. • This gives you the ability to write one function to handle multiple shortcodes. • This helps avoid duplication of code.Monday, November 7, 11
  • 8. Removing a shortcode: • remove_shortcode() • Lets you unregister an existing shortcode • This lets you replace other shortcodes with your own custom code.Monday, November 7, 11
  • 9. Running a shortcode: •do_shortcode() • This handles shortcode processing. • Run it on $content to nest shortcodes: [loop] [title] [content] [/loop]Monday, November 7, 11
  • 10. That’s It! • Now go forth and write shortcodes! • Any Questions?Monday, November 7, 11