Monday, 27 May 2013

issue with setting up permalink programmatically

issue with setting up permalink programmatically

I created a plugin to activate my theme using programming. i want to set default permalink using programming but it does't seems to work with custom post types. it works well with default custom post type.
I tried it on admin_footer hook with 9999 priority but not helped.
The code i used is:
add_action('admin_footer','default_permalink',9999);
function default_permalink(){
  if(get_option('change_permalink')!= 'post_name_permalink') {
  global $wp_rewrite;
  $wp_rewrite->set_permalink_structure( '/%postname%/' );
  $wp_rewrite->flush_rules();
  if(function_exists('flush_rewrite_rules')){
  flush_rewrite_rules(true);
   } //Set default permalink to postname end      
  update_option('change_permalink','post_name_permalink'); } }
Please help.

No comments:

Post a Comment