Support » Fixing WordPress » Tags aint replaced with add_rewrite_tag

  • Hi,

    im new in using WordPress, but i want to code a plugin that allows to use the Monthname in the permalinks as wild-card %monthname% to.

    The following code works, but if i dump the $rewrite object after calling the add_rewrite_tag method the %monthname% tag isnt replaced with the regex.

    class monthname {

    /* get_monthnames([$seperator])
    * this function return all monthnames out of the local.php
    * in a line seperted with the $seperator
    function get_monthnames($seperator='|') {
    global $month;

    $monthnames = '';
    foreach($month as $name) {
    // add seperator before the current monthname if this is NOT the first name
    if(!empty($monthnames)) {
    $monthnames .= $seperator;
    $monthnames .= $name;

    return $monthnames;

    function replace_monthname($rewrite) {
    $rewrite->add_rewrite_tag('%monthname%', '('.monthname::get_monthnames('|').')', 'monthname=');


    add_action('generate_rewrite_rules', array('monthname', 'replace_monthname'));

    Any ideas?

    For bettwer view:
    Example dump:
    string(49) "index.php?year=$matches[1]&%monthname%$matches[2]"

  • The topic ‘Tags aint replaced with add_rewrite_tag’ is closed to new replies.