Blackbams Blog
development – digital arts – internet
Knowledge is free. No one may take possession of it.
You do not want to use Attachment-Pages in your WordPress page? Or maybe you installed a gallery Plugin and want to transform all your Attachment URLs into File-URLs now? The following script will do this for you. Just make sure, that all relevant content blocks of your database run through this script.
function cis_file_links($content) {
$content = stripslashes($content);
$matches = array();
$attachment_urls = preg_match_all("/href=\"([-A-Z0-9+&@#\/%?=~_|!:,.;]*)\?attachment_id=([0-9]*)\"/siU",$content,$matches);
$urls = array();
foreach($matches[2] as $attachment) {
array_push($urls,wp_get_attachment_url($attachment));
}
// something went wrong with geting the attachments
if(count($matches[2])!=count($urls)) {
return $content;
}
for($i=0;$i
If you want to apply this script to every displayed content, for example, without changing any contents of your database, add this filter to your functions.php:
add_filter('the_content','cis_file_links');
Improvement ideas are welcome.
Warning: Undefined variable $time_since in /home/.sites/609/site1266/web/blackbams-blog/wp-content/themes/SilentWoodsByBlackbam/single.php on line 42 Dieser Eintrag wurde am 10. January 2012 um 22:22 in der Kategorie WP Scripts veröffentlicht. You can book the comments for this article RSS 2.0. Feedback, discussion, commendation and critics are welcome: Write a comment or trackback.
Tags: url conversion
Fatal error: Uncaught Error: Undefined constant "Ext_related_links" in /home/.sites/609/site1266/web/blackbams-blog/wp-content/themes/SilentWoodsByBlackbam/single.php:75 Stack trace: #0 /home/.sites/609/site1266/web/blackbams-blog/wp-includes/template-loader.php(106): include() #1 /home/.sites/609/site1266/web/blackbams-blog/wp-blog-header.php(19): require_once('/home/.sites/60...') #2 /home/.sites/609/site1266/web/blackbams-blog/index.php(17): require('/home/.sites/60...') #3 {main} thrown in /home/.sites/609/site1266/web/blackbams-blog/wp-content/themes/SilentWoodsByBlackbam/single.php on line 75internal_server_error