Internal links not updated after fixing permalinks

Hi everybody,

I migrated my wife’s blog to Wordpress using your description at Very good article, thanks! However I faced the following problem:

After the step “Fixing permalinks for imported post” all posts have the same URL they had at Blogger (fine), but the internal links within posts were not updated to this structure. So for example the URL of an article is:

but a link to this article in another article is still:

Is there a way to solve this problem without editing 1000 links manually?

Thanks in advance Hendrik


You can try search & replace plugin to change URLs inside post content. Hope that will help you.



Thanks for your reply @nitunlanjewar. Yes, some kind of search and replace with regular expressions is a good idea. However I don’t know how to exactly generate these short URLs. I somehow have to transfer what you did with the permalinks (script below) to the search and replace plugin.

<?php require_once('wp-load.php'); $res = $wpdb->get_results("SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = 'blogger_permalink'"); $wpdb->print_error(); foreach ($res as $row){ $slug = explode("/",$row->meta_value); $slug = explode(".",$slug[3]); $wpdb->query("UPDATE $wpdb->posts SET post_name ='" . $slug[0] . "' WHERE ID = $row->post_id"); $wpdb->print_error(); } echo "DONE"; ?>

That php script will only work with post URLs depends on slug, it will not search URL under post content.

Yes I know. I just meant that I need to do something similiar for links within posts, but I don’t know how. How are the built?

In your example below only the first 7 words are used for the Blogger URL. But this is not a fixed number. Sometimes more or less words are used.

That could be a more complicated things to first identify post URL (that must be your blog post URL) under post content by writing a php/SQL script and then you must write a code to map first word in URL with other existing URL which actually changed after fix.php file. And at the last update script to change those URL. I think this is how its complex. :expressionless: skip English vowels from URL along with “the” and some other words, and make smaller URL. But WordPress use the complete post title as a slug.

Thanks! Regarding the complexity I think editing the links manually seems to be the faster way.

Is it not possible to use the wp-cli ( “Search & Replace” functions?

Yeah, that will be a good option. :slight_smile:

There are about 600 broken links within my blog posts. Most of them go to different URLs. So a normal search & replace would not do the trick. If it was just the domain name or some other common string, search & replace would be a good idea of course.


I think you may be pleasantly surprised. How about a “Dry Run” to see? Try:

wp search-replace '' '' --dry-run

…paying special attention to the “Dry Run” flag, as it will go through the motions, but not make any changes.


     Show report, but don’t perform the changes.

Or maybe:

wp search-replace '' '' --recurse-objects --dry-run

…which I understand should dig into the theme and plugin files.


     Enable recursing into objects to replace strings.

Add the:


…flag if it is a network install (WPMU).

@bamajr Thanks for your detailed explanation. It think I have to explain my problem a little further. Currently I have a few hundred internal links in the blog like these two examples:

The only interesting part is the part after the last slash. These links do not work as the correct Permalinks for these examples are:

These permalinks where created with the fix.php presented on this website which applies a certain mechanism to shorten the links as shown. So I have a few hundred different links where I have to change the *.html with such a mechanism. I think this cannot be done via simple search and replace.

Indeed, search and replace can not help here. I have recently migrated my site from blogger to WP. So I can relate. But what you describe as your problem, doesn’t make sense.

You have a site on blogger. Your permalinks are Blogger-type. The internal links are pointing to Blogger-type permalinks.

Then you move to WP. You fix your permalinks to be Blogger-type or in other words to be the same that they were in Blogger. How is it possible that your internal links (that were imported with your posts from Blogger) suddenly changed from Blogger-type to something else? It’s impossible.

The only case I can think of, is that those links were created after you migrated to WP and before you fixed your permalinks.