Support » Plugin: Permalink Manager » Both change permalink and redirect to new url?

  • Resolved ctrlaltdelete

    (@ctrlaltdelete)


    Hi, i want to make sure before installing if this is the right plugin for the task.
    I have several Custom post types.
    I want to change the current permalink:
    domain.com/cpt1/%postname%/
    to
    domain.com/cpt1/%post_id%/

    And i also need it to redirect the old urls to the new ones. Preferably a 301 redirect.

    And i want to know if there would be a performance hit for doing this with say 6000 posts.

    Thanks.

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

    (@mbis)

    Hi @ctrlaltdelete

    unfortunately by default the plugin does not allow to change the last part of URI, but if it helps I can add a hook that would allow to replace the slug (postname) with ID.

    I did a small experiment and with no page cache enabled, an array with 6000 custom URIs would increase memory usage by approx. 1MB during page load.

    If you did not use any plugins for custom permalinks before and
    domain.com/cpt1/%postname%/

    is your native rewrite permastructure, you can enable the 301 redirect in plugin settings.

    Best Regards,
    Maciej

    • This reply was modified 2 months, 3 weeks ago by Maciej Bis.

    Wow thanks sorry for trouble! I have never used any plugin to change urls before. So it would redirect it just doesn’t have the feature to rewrite slugs on current version. Thanks again.

    • This reply was modified 2 months, 3 weeks ago by ctrlaltdelete.
    Plugin Author Maciej Bis

    (@mbis)

    Hi again @ctrlaltdelete

    please download and install 0.5.4 version from here:
    https://downloads.wordpress.org/plugin/permalink-manager.0.5.4.zip

    After it is done please add this filter to your (child) theme’s functions.php file:

    function permalink_manager_filter_slug($slug, $post) {
    	if($post->post_type == 'YOUR_CUSTOM_POST_TYPE_NAME') {
    		$slug = $post->ID;
    	}
    	return $slug;
    }
    add_filter('permalink_manager_filter_default_post_slug', 'permalink_manager_filter_slug', 99, 2);

    After it is done, please regenerate the permalinks for selected custom post type.

    • This reply was modified 2 months, 3 weeks ago by Maciej Bis.

    Ok i installed and activated that plugin.
    Added the code to functions php, replacing YOUR_CUSTOM_POST_TYPE_NAME with the actual post type name.
    Went to settings- permalinks and saved settings.
    But it had no effect nothing changed.

    Plugin Author Maciej Bis

    (@mbis)

    @ctraltdelete

    You also need to regenerate the permalinks in “Tools -> Regenerate/Reset” section (“Full URI” mode):

    /wp-admin/tools.php?page=permalink-manager&section=tools&subsection=regenerate_slugs

    • This reply was modified 2 months, 3 weeks ago by Maciej Bis.
    • This reply was modified 2 months, 3 weeks ago by Maciej Bis.

    It says “No slugs were updated!”

    Plugin Author Maciej Bis

    (@mbis)

    @ctrlaltdelete

    could you contact me via email contact [at] maciejbis.net?

    Plugin Author Maciej Bis

    (@mbis)

    @ctrlaltdelete

    I applied a fix, you have two options:

    1. you can remove the plugin and download & install it again from:
      https://downloads.wordpress.org/plugin/permalink-manager.0.5.4.zip (the pacakge contains fix)
    2. you can apply the fix manually – open:
      /wp-content/plugins/permalink-manager/includes/core/permalink-manager-post-uri-functions.php and replace it (line #133):
      $full_slug = get_page_uri($post);

      with:
      $full_slug = ($native_uri == false) ? apply_filters('permalink_manager_filter_default_post_slug', get_page_uri($post), $post) : get_page_uri($post);

    After you apply the fix, please regenerate the URIs one more time.

    If this does not help please contact me via email.

    Hi sorry for delay i couldn’t try yet but i will try today. Just 1 thing before i do. Is it possible to revert the changes with the plugin or the only way is restoring a database backup?

    Plugin Author Maciej Bis

    (@mbis)

    @ctrlaltdelete,

    as long as you do not change native slugs with “Custom & native slugs (post names)” mode in the bulk tools, you will not need to restore a database backup.

    My plugin uses custom array to store all the custom URIs and it is used to filter the permalinks only when the plugin is enabled.

    Ok i tried it did the job!
    The old urls respond 200 but still redirect. Would this be a problem with google? I mean not having 301 redirects.

    Also on “List of updated items”
    “Old slug” and “New Slug” remain the same, should i worry about that or it’s OK?

    Removing the function and regenerating urls once more does return them back to normal (pretty neat!).

    I have a question (hopefully the last one!): can this function take an array? like…

    function permalink_manager_filter_slug($slug, $post) {
    	if($post->post_type == 'array('apples','monkeys','carburetors')') {
    		$slug = $post->ID;
    	}
    	return $slug;
    }
    add_filter('permalink_manager_filter_default_post_slug', 'permalink_manager_filter_slug', 99, 2);

    thanks so much!

    Oh and will it affect new posts? I mean if i create a new post under those post types will they have the ID only by default?

    Plugin Author Maciej Bis

    (@mbis)

    @ctraltdelete

    Yes, you can use array inside the filter, but you need to correct it:

    function permalink_manager_filter_slug($slug, $post) {
    	if(in_array($post->post_type, array('apples','monkeys','carburetors'))) {
    		$slug = $post->ID;
    	}
    	return $slug;
    }
    add_filter('permalink_manager_filter_default_post_slug', 'permalink_manager_filter_slug', 99, 2);

    The filter does not affect the new posts, but it will in the next version of plugin.

    “Old slug” & “New slug” are changed only if you select the last mode, slug is a “post_name” key stored in wp_posts table in DB.

    • This reply was modified 2 months, 2 weeks ago by Maciej Bis.

    Excellent so i’ll wait cos i need to leave it running automatically for new posts. I’ll check back later on. Thanks!

    Plugin Author Maciej Bis

    (@mbis)

    Hi @ctraltdelete

    you’re welcome 🙂 I adjusted the code that is used to generate the sample permalink. Now the filter will work also with all the new posts (please update to 1.0.0 version).

    Best Regards,
    Maciej

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