Wordpress filename same as Post name - Keep Spaces and dashes

不羁的心 提交于 2019-12-25 18:24:57

问题


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:


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>';
}
?>


来源:https://stackoverflow.com/questions/13821989/wordpress-filename-same-as-post-name-keep-spaces-and-dashes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!