torounit/custom-post-type-permalinks

Is there a way to remove leading zeros from the month and day variables?

Closed this issue · 1 comments

Thanks for the great plugin!

I'm wondering if it can be used to remove the default leading 0 on the wordpress month and day variables? I added this code to a custom plugin - but it didn't help. I don't see any info about this in your documentation either.


add_filter( 'the_permalink', 't5_strip_leading_zeros_in_url' );
add_filter( 'month_link', 't5_strip_leading_zeros_in_url' );
add_filter( 'day_link',   't5_strip_leading_zeros_in_url' );

function t5_strip_leading_zeros_in_url( $url )
{
    // no pretty permalinks
    if ( ! $GLOBALS['wp_rewrite']->get_month_permastruct() )
    {
        return $url;
    }

    return str_replace( '/0', '/', $url );
}

source: https://wordpress.stackexchange.com/questions/65546/removing-leading-zeros-from-custom-permalink-structure

thanks

Try use post_type_link filter.