2016-02-11 93 views
2

我正在致力於一個項目,以幫助優化搜索引擎網站的內容,並且此插件中的所有圖片和鏈接不會拉動替代文字和標題投資組合中的圖像和錨點。投資組合圖片和鏈接上的替代文字和標題 - 揮舞投資組合

我已經瀏覽了waving-portfolio.php文件,看看這個問題可能源自哪裏,添加模塊和燈箱的圖像和鏈接的行不會拉動文本或標題。

我正在尋找一個快速修復的方法來爲該文件添加一些php行,以便數百個圖像和鏈接將ALT文本和標題歸因於它們。

以下是該文件的該部分在我正在處理的網站上顯示的內容。

if($width != 0){ 
$image_code = '<img src="'.$image[0].'" style="width:'.$width.'px" />'; 
}else 
{ 
$image_code = '<img src="'.$image[0].'" style="height:'.$height.'px" >'; 
} 

那麼我怎麼添加一些代碼的那些行,使其從介質庫中的圖像的替代文字和標題?

https://wordpress.org/plugins/waving-portfolio/

+0

嘗試:$ image_code = 「」; – Cuchu

+0

你寫什麼和現在已經有什麼不同?我想,我只是可以使用一些說明如何替換括號的句點將元數據歸因於圖像? –

+0

對不起,我看錯了 – Cuchu

回答

0
$title = $alt = get_the_title(); 
    if($width != 0){ 
    $image_code = '<img title="'.$title.'" alt="'.$alt.'" src="'.$image[0].'" style="width:'.$width.'px" />'; 
    }else 
    { 
    $image_code = '<img title="'.$title.'" alt="'.$alt.'" src="'.$image[0].'" style="height:'.$height.'px" >'; 
    } 
+0

定義$ title和$ alt – Cuchu

+0

http://www.w3schools.com/tags/tag_img.asp – Cuchu

+0

現在試試這個,我會讓你知道發生了什麼! –

0

我解決了這個缺乏SEO問題的揮舞組合和剛纔提交了更新,所有你需要做的就是刪除並重新安裝插件。

此修復程序也爲所有內部圖庫添加了「img」元信息。

這裏的一般優點是我添加的代碼來獲取附件的「alt」&「標題」(在我們的例子中是特色圖片)。在300線的「揮手-portfolio.php」裏我加了幾行代碼,以獲得所需的信息:

$image = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'single-post-thumbnail'); 

// Get the featured image ID 
$post_thumbnail_id = get_post_thumbnail_id(get_the_ID());  
// Retrieve the title of the image 
$title = get_the_title($post_thumbnail_id); 
// Retrieve the alternate text of the image 
$alt = get_post_meta($post_thumbnail_id, '_wp_attachment_image_alt', true); 

你可以看到在Demo page的影響,雖然我沒有給任何意義的標題圖像到目前爲止,但很快我會做:)

感謝