How do I link an image in my plugin so it displays on WordPress?

I'm creating a plugin for a college project. The plugin is very simple: it searches for name of the site address and upon finding it in a post, it outputs the site address with an image. However, I cannot get the code working. I've tried this:

?php
/*
Plugin Name: Murtaghs Trademark Plugin
Plugin URI: http://www.MurtaghsPubUndertakers.ie
Description: Adds Murtaghs Logo Wherever name Of Business Displayed On Page.
Author: Connell Gray
Version: 1.0
Author URI: http://www.MurtaghsPubUndertakers.ie
*/
function Murtaghs_Trademark_Plugin($text) {

    $site_name = get_bloginfo();
    //the logo.jpg file is stored in a folder called images which i  have created in the plugins folder//
    $new_site_name = $site_name . 'supecho 'img src="' . plugins_url( 'images/wordpress.png' ,"logo.jpg"  ) . '"  '/sup';

    $text = str_replace($site_name,$new_site_name,$text);

    return $text;
}
add_filter('the_content','Murtaghs_Trademark_Plugin');

? 

Topic plugins-url linking images plugins Wordpress

Category Web


This line is your problem:

$new_site_name = $site_name . '<sup>echo '<img src="' . plugins_url( 'images/wordpress.png' ,"logo.jpg"  ) . '" > '</sup>';

Here you've muddled up the quotes and put PHP code inside a string expecting it to still work.

e.g.

echo ' this is inside a quote:' inside a quote ' . ';

It doesn't work because the quote in your string closes the starting quote, ending the string. To fix this you need to either:

  • use a double quote
  • escape your characters

e.g.

echo 'this is inside a quote \' inside a quote \' .';

As a side note, make sure that your code editor supports syntax highlighting with a good colour scheme, it will make these kinds of issues more obvious.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.