conan
conan

Reputation: 1337

How to get img url and file url in jquery in wordpress plugin?

I am creating a plugin in wordpress. I am trying to get the img url and file url in jQuery. Code below. What did I do wrong?

$('.result_tag')
  .append('<img src="plugin_dir_url( __FILE__ ).'remove_sign.png'" >');

$.post("plugin_dir_url( __FILE__ ).'delete.inc.php'", {
    tag : text,/
  },
  function(data){
      $("#result_tag").html(data); 
});

Upvotes: 1

Views: 1005

Answers (1)

Castro Roy
Castro Roy

Reputation: 7823

supposing you are working in a .php file, you are missing the php tags <?php ?>

$('.result_tag')
  .append('<img src="<?php echo plugin_dir_url( __FILE__ ).'remove_sign.png' ?>" >');

$.post("<?php echo plugin_dir_url( __FILE__ ).'delete.inc.php' ?>", {
    tag : text,/
  },
  function(data){
      $("#result_tag").html(data); 
});

just change

'<img src="plugin_dir_url( __FILE__ ).'remove_sign.png'" >'

to

'<img src="<?php echo plugin_dir_url( __FILE__ ).'remove_sign.png' ?>" >'

Upvotes: 2

Related Questions