How to Export All WordPress URLs Easily with a Custom PHP Tool

Codeable.io

How to Export All WordPress URLs Easily

If you manage a WordPress website, there are times when you need a full list of URLs for migrations, SEO audits, or redirects. While plugins can help, sometimes a simple PHP snippet is faster and lighter. In this guide, we’ll show you a ready-to-use Full URL Export Tool that exports all public URLs from your WordPress site.

Why You Might Need to Export WordPress URLs

Exporting all your URLs can be useful for:

  • Website migration: Ensure no URLs are lost when moving to a new domain.
  • SEO audits: Check for broken links or crawl issues.
  • Redirect planning: Prepare .htaccess or plugin-based redirects for outdated pages.

If you’re looking for official WordPress resources on migrations, check out WordPress Codex: Moving WordPress.

The PHP Snippet to Export All URLs

Here’s a ready-to-use snippet that exports every public URL, including:

  • Posts, pages, and custom post types
  • Categories, tags, and other taxonomies
  • Homepage and post type archives
// Uncomment to enable temporarily
add_action('init', 'developry_export_all_urls');

function developry_export_all_urls() {
    if ( !isset($_GET['export_urls']) ) return;

    header('Content-Type: text/plain; charset=utf-8');

    $output_url = function($url) {
        if ($url && !is_wp_error($url)) {
            echo esc_url($url) . "\n";
        }
    };

    echo "### Exporting all public URLs from WordPress ###\n\n";

    $post_types = get_post_types(['public' => true], 'names');

    foreach ($post_types as $post_type) {
        echo "\n# Post Type: $post_type\n";
        $posts = get_posts([
            'numberposts' => -1,
            'post_type'   => $post_type,
            'post_status' => 'publish'
        ]);
        foreach ($posts as $post) $output_url( get_permalink($post) );
        if ($archive_link = get_post_type_archive_link($post_type)) $output_url($archive_link);
    }

    echo "\n# Taxonomies\n";
    $taxonomies = get_taxonomies(['public' => true], 'names');
    foreach ($taxonomies as $taxonomy) {
        $terms = get_terms(['taxonomy' => $taxonomy, 'hide_empty' => false]);
        foreach ($terms as $term) $output_url( get_term_link($term) );
    }

    echo "\n# Homepage\n";
    $output_url( home_url('/') );

    echo "\n### Export complete ###";
    exit;
}

How to Use This Tool

  1. Paste the code in your theme’s functions.php or a custom plugin.
  2. Uncomment the add_action line to enable temporarily.
  3. Visit: https://yourdomain.com/?export_urls=1
  4. Copy the output and save it as .txt or .csv.
  5. Re-comment the add_action line to prevent unauthorized access.

This approach avoids installing bulky plugins while giving you full control over your URLs.


Important Notes

  • Always backup your site before adding custom code.
  • Only enable the snippet temporarily to prevent unauthorized access.
  • Works for all public post types and taxonomies, including custom ones.

For more advanced migration strategies, read this Smashing Magazine guide on WordPress migrations.

Conclusion

Exporting WordPress URLs doesn’t need to be complicated. With this lightweight PHP snippet, you can generate a complete list of URLs in seconds, making it perfect for migrations, redirects, and SEO audits.

By leveraging this tool, you save time, avoid plugin bloat, and maintain full control over your WordPress site structure.

Leave a Reply

Your email address will not be published. Required fields are marked *