10. January 2012
von Blackbam
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) {
	// something went wrong with geting the attachments
	if(count($matches[2])!=count($urls)) {
		return $content;
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:
Improvement ideas are welcome.

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.


Warning: Use of undefined constant Ext_related_links - assumed 'Ext_related_links' (this will throw an Error in a future version of PHP) in /home/.sites/609/site1266/web/blackbams-blog/wp-content/themes/SilentWoodsByBlackbam/single.php on line 75

No comments yet

Kommentare abonnieren (RSS) or URL Trackback

Leave a comment: