Changing the slug or permalink in Easy Digital Downloads

June 20, 2018| demoplanet

We use Easy Digital Downloads to sell digital goods online, each products has a unique URL. By default Easy Digital Downloads permalink looks like this:

http://yourshop.com/downloads/abc-download/

If you check a closer look you will find that on every product URL, Easy Digital Downloads uses the “downloads” slug . This is the default slug created by the EDD plugin. Based on what you are selling online, you may wish to change this to better suit your needs. If you are selling e-book online, it would be better to change it to something like “books”.

Please follow the following steps to do this slug change.

  1. Open your theme’s functions.php file.
  2. EDD_SLUG : Copy the following code and paste it into the functions.php for slug change:

    
    if ( ! defined( 'EDD_SLUG' ) ) {
        define( 'EDD_SLUG', 'books' );
    }
    
  3. Label : Change the Admin Dashboard Label for Download post type: Add the below code in functions.php file.
    
    <?php function set_download_labels($labels) { $labels = array( 'name' => _x('Themes', 'post type general name', 'your-domain'),
    		'singular_name' => _x('Book', 'post type singular name', 'your-domain'),
    		'add_new' => __('Add New', 'your-domain'),
    		'add_new_item' => __('Add New Book', 'your-domain'),
    		'edit_item' => __('Edit Book', 'your-domain'),
    		'new_item' => __('New Book', 'your-domain'),
    		'all_items' => __('All Books', 'your-domain'),
    		'view_item' => __('View Book', 'your-domain'),
    		'search_items' => __('Search Books', 'your-domain'),
    		'not_found' =>  __('No Books found', 'your-domain'),
    		'not_found_in_trash' => __('No Books found in Trash', 'your-domain'), 
    		'parent_item_colon' => '',
    		'menu_name' => __('Books', 'your-domain'),
    		'featured_image'        => __( '%1$s Image', 'easy-digital-downloads' ),
    		'set_featured_image'    => __( 'Set %1$s Image', 'easy-digital-downloads' ),
    		'remove_featured_image' => __( 'Remove %1$s Image', 'easy-digital-downloads' ),
    		'use_featured_image'    => __( 'Use as %1$s Image', 'easy-digital-downloads' ),
    	);
    	return $labels;
    }
    add_filter('edd_download_labels', 'set_download_labels');
           
  4. Save : functions.php
  5. Permalinks : To avoid  “page not found” issues or redirect to attachment image we need to re write the permalinks rules via admin dashboard : Go to Settings -> Permalinks and just save the changes. It will flush the rewrite rules.
  6. SEO: finally, we need to redirect old URLs to new one . Just copy the rewrite codes below to .htaccess file in your root directory of hosting.
    RedirectMatch 301 /downloads/(.*) https://yourshop.com/books/$1
  7. Done!
Categories: Tips and Tricks

Leave a Reply

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

Rating*