add_rewrite_tag example



    /** * Retrieves all of the rewrite rules for pages. * * @since 1.5.0 * * @return string[] Page rewrite rules. */
    public function page_rewrite_rules() {
        // The extra .? at the beginning prevents clashes with other regular expressions in the rules array.         $this->add_rewrite_tag( '%pagename%', '(.?.+?)', 'pagename=' );

        return $this->generate_rewrite_rules( $this->get_page_permastruct(), EP_PAGES, true, true, false, false );
    }

    /** * Retrieves date permalink structure, with year, month, and day. * * The permalink structure for the date, if not set already depends on the * permalink structure. It can be one of three formats. The first is year, * month, day; the second is day, month, year; and the last format is month, * day, year. These are matched against the permalink structure for which * one is used. If none matches, then the default will be used, which is * year, month, day. * * Prevents post ID and date permalinks from overlapping. In the case of * post_id, the date permalink will be prepended with front permalink with * 'date/' before the actual permalink to form the complete date permalink * structure. * * @since 1.5.0 * * @return string|false Date permalink structure on success, false on failure. */
$this->registry->add_provider( $name$provider );
        }
    }

    /** * Registers sitemap rewrite tags and routing rules. * * @since 5.5.0 */
    public function register_rewrites() {
        // Add rewrite tags.         add_rewrite_tag( '%sitemap%', '([^?]+)' );
        add_rewrite_tag( '%sitemap-subtype%', '([^?]+)' );

        // Register index route.         add_rewrite_rule( '^wp-sitemap\.xml$', 'index.php?sitemap=index', 'top' );

        // Register rewrites for the XSL stylesheet.         add_rewrite_tag( '%sitemap-stylesheet%', '([^?]+)' );
        add_rewrite_rule( '^wp-sitemap\.xsl$', 'index.php?sitemap-stylesheet=sitemap', 'top' );
        add_rewrite_rule( '^wp-sitemap-index\.xsl$', 'index.php?sitemap-stylesheet=index', 'top' );

        // Register routes for providers.
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 );
}

/** * Removes an existing rewrite tag (like %postname%). * * @since 4.5.0 * * @global WP_Rewrite $wp_rewrite WordPress rewrite component. * * @param string $tag Name of the rewrite tag. */
        if ( false !== $this->query_var && $wp ) {
            $wp->add_query_var( $this->query_var );
        }

        if ( false !== $this->rewrite && ( is_admin() || get_option( 'permalink_structure' ) ) ) {
            if ( $this->hierarchical && $this->rewrite['hierarchical'] ) {
                $tag = '(.+?)';
            } else {
                $tag = '([^/]+)';
            }

            add_rewrite_tag( "%$this->name%", $tag$this->query_var ? "{$this->query_var}=" : "taxonomy=$this->name&term=" );
            add_permastruct( $this->name, "{$this->rewrite['slug']}/%$this->name%", $this->rewrite );
        }
    }

    /** * Removes any rewrite rules, permastructs, and rules for the taxonomy. * * @since 4.7.0 * * @global WP $wp Current WordPress environment instance. */
    

    public function add_rewrite_rules() {
        global $wp_rewrite$wp;

        if ( false !== $this->query_var && $wp && is_post_type_viewable( $this ) ) {
            $wp->add_query_var( $this->query_var );
        }

        if ( false !== $this->rewrite && ( is_admin() || get_option( 'permalink_structure' ) ) ) {
            if ( $this->hierarchical ) {
                add_rewrite_tag( "%$this->name%", '(.+?)', $this->query_var ? "{$this->query_var}=" : "post_type=$this->name&pagename=" );
            } else {
                add_rewrite_tag( "%$this->name%", '([^/]+)', $this->query_var ? "{$this->query_var}=" : "post_type=$this->name&name=" );
            }

            if ( $this->has_archive ) {
                $archive_slug = true === $this->has_archive ? $this->rewrite['slug'] : $this->has_archive;
                if ( $this->rewrite['with_front'] ) {
                    $archive_slug = substr( $wp_rewrite->front, 1 ) . $archive_slug;
                } else {
                    $archive_slug = $wp_rewrite->root . $archive_slug;
                }

                
Home | Imprint | This part of the site doesn't use cookies.