I am new to wordpress plugins & running wordpress on my wamp server on my laptop and I have written & activated this on my wordpress site (site name: lifyog) on the same server on my desktop. Function written in plugin is supposed to add image with every post, however it is not working. Please help in correcting the code.
I have checked the image source this is ok.
My plugin is at following address:
wamp/www/wordpress/wp-content/plugins/Wpplugin
File name is addimage.php
Code of plugin is as under:
<?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");
?>
The $imagewithtext variable declare on line 14 is overwriting the $imagewithtext variable that you have wrote on the line 13.
You can change the equal sign “=” to dot equal sign “.=”, this will help you to add the $post variable value to $imagewithtext variable and not overwrite it
$imagewithtext .= $post;
not$imagewithtext = $post;
I believe this will do the trick