Go Bananas!

The one and only banana blog.
Put on your safety goggles.

WordPress Media titles being changed to a slug

Posted September 22nd, 2016 @ 4:29 PM by

Recently a client informed MontanaB that their newly uploaded WordPress media file titles were suddenly being renamed to a slug format (since early September 2016). For example, an uploaded file named “Website Logo.jpg” was being changed to “website-logo” in the title, when it should be “Website Logo”. While this is correct behavior for file names, it can become an issue for the title, especially if the title is being referenced on the website front end.

After troubleshooting and researching the issue, I found that this was a bug from the most recent WordPress 4.6.1 release where the title was being sanitized along with the file name. You can read more about this change at https://core.trac.wordpress.org/changeset/38538

While the intentions of sanitizing the title is great, the sanitation was a little too aggressive. To correct this behavior we can add in our functions.php the following code:

function wp37989_fix_encoded_attachment_titles( $data, $postarr ){
      $basename = pathinfo( $postarr['file'], PATHINFO_BASENAME );
      $data['post_title'] = preg_replace("/-/", " ", sanitize_text_field( $basename ));
      return $data;
add_filter('wp_insert_attachment_data', 'wp37989_fix_encoded_attachment_titles', 10, 2 );


We advise our clients to use WordPress if they have information-only needs AND they know they already like the Content Management System (CMS) admin panel. Without question, the Wordpress admin panel is the sexiest and easiest to use. Also, Wordpress begins to have a harder time with transactions and management features than do its open source competitors. Wordpress has been around since 2003. For the first few years, it was the most recommended blogging software for your blogging website. The open source community surrounding Wordpress knew there was so much more it could do. This huge community completely overhauled the code in an effort to make it easier for coders to build ANYTHING on top of the CMS. This custom code is typically packaged for use by other developers either for free or for a fee. There are roughly 28,000 plugins we have access to (that is a LOT). This all leads up to a 2011 award for Wordpress of the Open Source App of the year . Montana Banana Web Development employs veteran Wordpress contributing coders and knows when to use (or when to discourage use of) Wordpress.

Learn More

Eric made his first website in 1994 to the tune of Angelfire and never looked back. While stationed in Hawaii during his time in the military, he started to teach himself the LAMP stack and continued to improve until he finished his enlistment in 2006. At that time he began freelancing while also working a range of development positions, from small web development companies to large advertisement agencies.