2015-04-12 84 views
1

我是新的wordpress插件&在我的筆記本電腦上我的wamp服務器上運行wordpress,我寫了&在我的wordpress網站(站點名稱:lifyog)我的桌面。寫在插件中的函數應該爲每個帖子添加圖像,但它不起作用。請幫助糾正代碼。插件激活,但不能在桌面上的wordpress工作

我已檢查圖片來源這很關鍵。

我的插件是在以下地址:

wamp/www/wordpress/wp-content/plugins/Wpplugin 

文件名是addimage.php

插件的代碼是爲下:

<?php 
/* 
Plugin Name: Add Image 
Plugin URL:http//wordpress 
Version: 1.0 
Author: wordpress 
Author URL: http://localhost/wordpress 
Description: This plugin automatically adds an image at the beginning of every post 
*/ 

function addImage($post) 
{ 
$imagewithtext="<img src='http://localhost/wordpress/wp-content/themes/twentyfifteen/Images/veer.jpg' height='70px' width='70px' align='left'>"; 
$imagewithtext=$post; 
return $imagewithtext; 

} 

add_filter("the_content","addImage"); 
?> 

回答

1

的$ imagewithtext變量聲明上線14覆蓋$ linewithtext變量,你已經寫在行13上。

可以更改等號「=」,以點等號「=」,這將幫助你在$後變量的值添加到$ imagewithtext變量,而不是覆蓋它

$imagewithtext .= $post;$imagewithtext = $post;

我相信這會做詭計

+0

非常感謝你的工作 – user3811050

相關問題