Sunday, January 5, 2014

Renaming Locally Saved Image Names In FeedWordPress Advanced Filters


FeedWordPress Advanced Filters

FeedWordPress Advanced Filters (FAF) is a Wordpress plugin and an extension for FeedWordPress plugin. FAF has many important features, such as the ability to remove specific keywords or HTML tags, save images locally with or without a pre-defined size, setting featured images and much more.

When the images are saved locally, they maintain their original name from the original website. Sometimes this name consists of random characters, a long series of numbers or the original websites name.

Modifying The Code

All this can be changed easily by modifying one line of the code. What I'm going to do is change the name of the image to the following format:

For example:

To apply the changes, open /wp-content/plugins/faf/filters/image_filters.php with a text editor, and scroll down to line 423 (in version 0.6), or search for the following line:

$filename = $pathinfo["filename"] . "." . $imgext;

And change it to:

$filename = strtolower(str_replace(" ", "-", $post["post_title"])) . '-' . str_replace('http://',"",get_site_url() ) . '-' . rand(0,time()/1000) . "." . $imgext;

Save the file and upload if necessary.

The first part will rename the image as same as the post title but in lowercase and replace the spaces with dashes. The second part will append the website URL without the http:// part. The third part will generate a random number based on the current time. While the fourth part will append the image extension to the filename.

This method can also help the on-page SEO by giving the images a clear and descriptive name.

Any questions? Please leave your comment below!