Forums

Changing Monthnum to Monthname in Permalink (2 posts)

  1. blackproof
    Member
    Posted 9 months ago #

    i am trying to change the permalink structure on my blog , i have successfully implemented , the permalink has changed but it redirects to a 404 page.

    check code.

    add_filter('post_link', 'rating_permalink', 10, 3);
    add_filter('post_type_link', 'rating_permalink', 10, 3);
    
    function rating_permalink($permalink, $post_id, $leavename) {
    	if (strpos($permalink, '%monthname%') === FALSE) return $permalink;
    
            // Get post
            $post = get_post($post_id);
            if (!$post) return $permalink;
    
            // Get taxonomy terms
            $month= strtolower(get_the_time('M', $post->ID));	
    
    	return str_replace('%monthname%', $month, $permalink);
    }
  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 9 months ago #

    All that code does is to change the permalink that is output. It doesn't actually make the permalink work in any real meaningful way.

    You'll need to hook into the rewrite system to parse the URLs and return the correct query variables to retrieve the data.

Reply

You must log in to post.

About this Topic