<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>url conversion &#8211; Blackbams Blog</title>
	<atom:link href="https://blog.blackbam.at/tag/url-conversion/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.blackbam.at</link>
	<description>development - digital arts - internet</description>
	<lastBuildDate>Wed, 11 Jan 2012 22:05:06 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.1</generator>
	<item>
		<title>Convert WordPress attachment URLs into file URLs</title>
		<link>https://blog.blackbam.at/2012/01/10/convert-wordpress-attachment-url-into-file-url-automatically/</link>
					<comments>https://blog.blackbam.at/2012/01/10/convert-wordpress-attachment-url-into-file-url-automatically/#respond</comments>
		
		<dc:creator><![CDATA[Blackbam]]></dc:creator>
		<pubDate>Tue, 10 Jan 2012 20:44:53 +0000</pubDate>
				<category><![CDATA[WP Scripts]]></category>
		<category><![CDATA[url conversion]]></category>
		<guid isPermaLink="false">https://blog.blackbam.at/?p=1789</guid>

					<description><![CDATA[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) { [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>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. </p>
<pre lang="php">
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<count($urls);$i++) {
		$repl = "href=\"".$urls[$i]."\"";
		$content = preg_replace("/href=\"([-A-Z0-9+&#038;@#\/%?=~_|!:,.;]*)\?attachment_id=([0-9]*)\"/siU",$repl,$content,1);
	}
 
	return $content;
}
</pre>
<p>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:</p>
<pre lang="php">
add_filter('the_content','cis_file_links');
</pre>
<p>Improvement ideas are welcome.</p>
<p><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fblog.blackbam.at%2F2012%2F01%2F10%2Fconvert-wordpress-attachment-url-into-file-url-automatically%2F&#038;title=Convert%20WordPress%20attachment%20URLs%20into%20file%20URLs" data-a2a-url="https://blog.blackbam.at/2012/01/10/convert-wordpress-attachment-url-into-file-url-automatically/" data-a2a-title="Convert WordPress attachment URLs into file URLs"><img src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.blackbam.at/2012/01/10/convert-wordpress-attachment-url-into-file-url-automatically/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
