Skip to content
Article

How to Bulk Delete Filtered Aliases in Drupal 7 without a Module

The Pathauto module provides a great interface in Drupal 7 for customizing your URLs, but what happens when you change your mind later? Bulk delete. But you don’t have fine control over limited subsets, you can only delete entire alias types (nodes, taxonomy, etc). Sure you could do this in the database as well — if you have access. Our Drupal experts have a solution!

Here’s how to automate clearing out a filtered subset of your alias list (e.g. for a specific taxonomy) from within your browser. There may be modules that probably do this, but I like hacking around in the developer console.

  1. Install Pathauto first :)
  2. Navigate to Configuration » URL aliases
  3. Filter your aliases from the “List” tab
  4. Run the following jQuery snippet in your developer console (F12)

Update: originally restricted context to #block-system-main, it seems that #content is “safer”
[javascript]
(function($){
$deletes = $(‘li.delete a’, ‘#content’);

// loop delete links
$deletes.each(function(i,o){
// jquery
var $o = $(o);

// “click” delete link
$.get( $o.attr(‘href’), function(data){
// get
var $delform = $(data).find(‘#path-admin-delete-confirm’)
, confirm = $delform.attr(‘action’)
;

console.log( $delform.serialize() );
// now “submit” the delete form
$.post( confirm, $delform.serialize(), function(){
console.log( ‘killed ‘ + $o.attr(‘href’) );
}); // submit (post)

}); // click (get)
}); // each

})(jQuery);
[/javascript]

Essentially, it just walks through your list of links, fires each asynchronously, waits for the confirmation form, and then fires that form asynchronously as well. Continue to follow our blog for more great tips like this one from our Drupal experts at Atlantic BT.

Update — check out this script modification for a more generic format that can be reused for just about any bulk update process in Drupal. More great tips from our Drupal experts!

The Atlantic BT Manifesto

The Ultimate Guide To Planning A Complex Web Project

Insights

Atlantic BT's Insights

We’re sharing the latest concepts in tech, design, and software development. Learn more about our findings.

Questions & Answers

Are there differences in application architecture that are important for the cloud?
It is important to build applications and workloads specifically for the cloud. You will want to carefully consider what services the cloud provider of your choice has to offer and how your application leverages those services.
Learn More about Are there differences in application architecture that are important for the cloud?
Are there any drawbacks to cloud hosting?
Yes, there will always be some risks associated with any hosting option. You are relying on the resiliency and engineering of infrastructure that has scaled at an astounding rate.
Learn More about Are there any drawbacks to cloud hosting?
What’s the benefit of hosting in the cloud vs. traditional options?
Reasons not to host in the cloud are few and far between. If you don't host in the cloud, you will spend more in both CapEx and OpEx to manage your applications or websites in a traditional environment.
Learn More about What’s the benefit of hosting in the cloud vs. traditional options?
How can I improve the performance of my application?
There are several primary reasons that applications perform poorly, and in some cases it’s a combination of several. 1) Data latency: If your application is making calls to a data source (whether it’s an API or a direct call) and there is latency at the data provider, your application performance will suffer.
Learn More about How can I improve the performance of my application?
Should I move my application to the cloud?
The answer is ‘probably yes’. There aren’t many reasons for an application to be hosted elsewhere, aside from occasional compliance standards, or requirements to integrate with local services that would require large amounts of data to move from on-premise to cloud.
Learn More about Should I move my application to the cloud?
Where should my application be hosted?

There are many different options for hosting, but most applications would do well with one of the cloud providers -- Amazon Web Services, Google Cloud Platform, Microsoft Azure.

Learn More about Where should my application be hosted?