Revisions
- April 19, 2013 @ 16:05:38 [Current Revision] by PeterLugg
- April 19, 2013 @ 16:02:35 by PeterLugg
Revision Differences
April 19, 2013 @ 16:02:35 | Current Revision | ||
---|---|---|---|
Content | |||
Added: Taken from: <a href="http:// www.tcbarrett.com/2011/09/ wordpress-the_ slug-get-post- slug-function/" target="_blank" >http://www.tcbarrett.com/ 2011/09/wordpress-the_slug- get-post-slug- function/</a> | |||
Added: Using basename() and get_permalink() to retrieve post slug | |||
Added: [php]</pre> | |||
Added: <?php echo( basename(get_ permalink()) ); ?> | |||
Added: <pre>[/php] | |||
Added: Using global $post object to retrieve post slug | |||
Added: [php]</pre> | |||
Added: <?php global $post; echo $post->post_name; ?> | |||
Added: <pre>[/php] | |||
Added: | |||
Added: Fully hookable function to retrieve the post slug | |||
Added: [php] | |||
Added: function the_slug($echo=true){ | |||
Added: $slug = basename(get_ permalink()); | |||
Added: do_action('before_slug', $slug); | |||
Added: $slug = apply_filters( 'slug_filter', $slug); | |||
Added: if( $echo ) echo $slug; | |||
Added: do_action('after_slug', $slug); | |||
Added: return $slug; | |||
Deleted: | Added: } | ||
Added: [/php] | |||
Added: This provides you with a simple way retrieve and display the post slug. I find this useful for applying unique CSS ids and classes to my HTML mark up. | |||
Added: [html] | |||
Added: <div id="some- post-container-<?php the_slug();?>"> | |||
Added: Lorem whatsit here | |||
Added: </div> | |||
Added: [/html] |
Note: Spaces may be added to comparison text to allow better line wrapping.
No comments yet.