Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




add_rewrite_tag [ WordPress Function ]

add_rewrite_tag ( $tag, $regex, $query = '' )
Parameters:
  • (string) $tag Name of the new rewrite tag.
  • (string) $regex Regular expression to substitute the tag for in rewrite rules.
  • (string) $query String to append to the rewritten query. Must end in '='. Optional.
See:
Defined at:



Add a new rewrite tag (like %postname%).

The $query parameter is optional. If it is omitted you must ensure that you call this on, or before, the 'init' hook. This is because $query defaults to "$tag=", and for this to work a new query var has to be added.

Source


<?php
function add_rewrite_tag$tag$regex$query '' ) {
    
// validate the tag's name
    
if ( strlen$tag ) < || $tag[0] != '%' || $tagstrlen($tag) - ] != '%' )
        return;

    global 
$wp_rewrite$wp;

    if ( empty( 
$query ) ) {
        
$qv trim$tag'%' );
        
$wp->add_query_var$qv );
        
$query $qv '=';
    }

    
$wp_rewrite->add_rewrite_tag$tag$regex$query );
}
?>

Examples [ wp-snippets.com ]

Google Arama Sonuçlarý

Dahasý ...

0 User Note(s)

Henüz yok. Ýlk sen ol!

Yeni Ekle ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics