Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save WenLiangTseng/6051664 to your computer and use it in GitHub Desktop.
Save WenLiangTseng/6051664 to your computer and use it in GitHub Desktop.
讓WP中文圖片網址符合W3C檢驗(讓get_the_post_thumbnail()符合W3C檢驗的方法)
<?php
//讓Wordpress的中文圖片網址符合W3C檢驗的方法
//讓get_the_post_thumbnail()符合W3C檢驗的方法
//也就是說,讓中文的網址經過一層URL編碼
$thumbnail_id = get_post_thumbnail_id($post->ID);
$src = wp_get_attachment_image_src( $thumbnail_id );
echo get_the_post_thumbnail($post->ID, 'thumbnail', array(
'src' => 'http://'.str_replace('%2F', '/', urlencode(substr($src[0], 7))),
'alt' => trim(strip_tags( $attachment->post_excerpt )),
'title' => trim(strip_tags( $attachment->post_title )),
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment