Wordpress filename same as Post name - Keep Spaces

2019-09-08 20:07发布

I have it set so that the filnename matches the post title using the following code.

As of right now all spaces and dashes are stripped out.

example - "Post Title 2012-2013" becomes "PostTitle20122013.mp3"

I would like to maintain spaces and dashes in the filename.

Files are all .mp3. As when you purchase music from iTunes spaces and dashes are "OK" and preferred.

can anyone help me with the code to allow this?

Here is my current code that is place in the loop...

<?php $customField = get_post_custom_values("audio"); if (isset($customField[0])) { echo '<h3><a href="'.$customField[0].'" class="button">'.get_the_title().'</a></h3>'; } ?>

1条回答
劫难
2楼-- · 2019-09-08 20:55

I have no idea why the dashes are being stripped out, but you can try this to keep the spaces

<?php
$post_title = urlencode(get_the_title());
$customField = get_post_custom_values("audio");
if (isset($customField[0])) {
 echo '<h3><a href="'.$customField[0].'" class="button">'.$post_title.'</a></h3>';
}
?>
查看更多
登录 后发表回答