Support » Plugin: Permalink Manager Lite » %monthnum2% cannot be read

  • Resolved Helen Grace Tacang

    (@helentacang)


    I tried adding /%monthnum2%/ on the permalink structure to remove the 0 on the months and dates but it’s not being read by the plugin. It removes the month and day on the URL slug instead.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Maciej Bis

    (@mbis)

    Hi @helentacang,

    This tag is not included neither in Permalink Manager nor WordPress core codebase.

    Actually, I have found that this tag (with a custom code snippet and detailed instructions) is mentioned only in this article:
    https://wordpress.stackexchange.com/a/330933/38240

    Unfortunately, to remove the trailing zeros with my plugin you will need to use code snippet:

    /**
     * Use single-digit month number in permastructures
     * Use %monthnum2% or %daynum2% in "Permastructure" settings
     */
    function pm_date_tags($default_uri, $post) {
    	if(empty($post->post_type)) {
    		return $default_uri;
    	}
    
    	if(strpos($default_uri, '%monthnum2%') !== false) {
    		$monthnum = date('n', strtotime($post->post_date));
    		$default_uri = str_replace('%monthnum2%', $monthnum, $default_uri);
    	}
    	
    	if(strpos($default_uri, '%daynum2%') !== false) {
    		$daynum = date('j', strtotime($post->post_date));
    		$default_uri = str_replace('%daynum2%', $daynum, $default_uri);
    	}
    
    	return $default_uri;
    }
    add_filter('permalink_manager_filter_permastructure', 'pm_date_tags', 5, 2);

    Please simply paste it to functions.php in your child theme directory. Then you will be able to use both %monthnum2% and %daynum2% in Permastructure settings.

    Best regards,
    Maciej

    Thread Starter Helen Grace Tacang

    (@helentacang)

    Thanks, Maciej!!

    I tried it out and it’s working 🙂

    Plugin Author Maciej Bis

    (@mbis)

    Hi @helentacang,

    I am happy to help 😉

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.