Shortcodes

WordPress allows developers to define shortcodes—bracketed words that are replaced with content when the post is displayed to visitors. Shortcodes work like text macros in Microsoft Word. WordPress itself uses shortcodes to insert some forms of media (photos with captions, image galleries). A typical image caption shortcode is shown in Figure 4-5, and the resulting image display (in the Twenty Ten theme) is shown in Figure 4-6.

\ + l,i>fhltp://wp.trünÍ!/wp-adfn¡nípost.php?poEt=lSacl¡or'=ed¡t

Testing Trunk Search angines Blocke!

¿P Edit Post Helio world!

Permalink: srtp: I '*p.trurik/?r)^ 1 CJvanse Permalinks ViewPnsr U pi cad / Insert @ [3 *

Edit Post < Testing Trunk — WordPress

P ID

Vis u si HTML

link b-quote tíet ins img ul ol I code more lookup close tags

[caption id="atlachment_6" align="aligncenter" width="300" captiongreen pattern"J<a href="http://wp.trunk/wp-content/uploads/2010/03/220E30_63711.jpg"><img class="size-mecium wp-image-6" title="2205 30_6371" src="http//wptrunk/wp-content/uploads/201Q/03/2205 30_63711-300x225.jpg" alt="" width= "300" height="225" /></a>[/caption]

Edit Posts * Howdy. admin Log Out

Screen Options Help

Preview Changes

Status: Published Edit Visibility: Public Ed]t

Published on: Mar 21, 2010 ¡S 18:57 Edit

Move ro Trash

Categories

All Categories Most Used Ijí Uncategorized

Word count: ;

Last edited by admin on April LO, 2010 at 3:50 a

Excerpt

optional ha-td-crafted simii

Taries of your com

cent that ca

n be used in vour theme. Learn more about manual exrerots.

Send Trackbacks

Figure 4-5. An image caption shortcode

Figure 4-6. The image display resulting from the caption shortcode

You might install plugins that provide more shortcodes. For example, if you have pieces of content that you'd like to write once and reuse throughout your site, you could define your own shortcodes using a plugin like Post Snippets (Figure 4-7) or Reusables.

TW( 4 Ihr blent erf I»»« nt HTUt tu Inwl In Ih* pent atwi you ipt*it 1h> wppvl Irm-n lh» Inir" bulton m Iii« TinyttCf p-ir%*i in ths pMl «du en IT you Km pnlernii pmSpfliwd vinitin you (an r«f«renc* them from tin Snippet enclosing them in 0 tfictels.

TW( 4 Ihr blent erf I»»« nt HTUt tu Inwl In Ih* pent atwi you ipt*it 1h> wppvl Irm-n lh» Inir" bulton m Iii« TinyttCf p-ir%*i in ths pMl «du en IT you Km pnlernii pmSpfliwd vinitin you (an r«f«renc* them from tin Snippet enclosing them in 0 tfictels.

To refer*«* lb* vjri»Wei m the txvnplc above, you *c-jW <oier |uf1] jnd |iwmc I So if vbu «nur Bits wilpsd

Figure 4-7. Post Snippets lets you define new shortcodes. It gives you the option to place corresponding buttons on the editors' toolbars.

To create a snippet, enter the shortcode you'd like to use into the Title field, as shown in Figure 4-7. Then enter the expanded version in the Snippet field. You'll see the shortcode while editing the post, as shown in Figure 4-8, but when a visitor views the post, she'll see the expanded version, as shown in Figure 4-9.

Figure 4-8. The post snippet in the post editor
Figure 4-9. The expanded snippet
0 0

Post a comment