Created
July 22, 2013 06:19
-
-
Save WenLiangTseng/6051664 to your computer and use it in GitHub Desktop.
讓WP中文圖片網址符合W3C檢驗(讓get_the_post_thumbnail()符合W3C檢驗的方法)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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