0

I'm wanting to add a URL link into the image upload error message, but it's only printing the string, not adding the hyperlink. I'm using the code below

  function my_max_image_size( $file ) {
  $size = $file['size'];
  $size = $size / 1024;
  $type = $file['type'];
  $is_image = strpos( $type, 'image' ) !== false;
  $limit = 750;
  $link = '<a href="example.com">';
  $limit_output = '750kb';
  if ( $is_image && $size > $limit ) {
    $file['error'] = 'Image files must be smaller than ' . $limit_output . '<a href="example.com"> Click here to get help</a> ';

// not working either 
 // if ( $is_image && $size > $limit ) {
  //  $file['error'] = 'Image files must be smaller than ' . $limit_output . 'Click here to get help: '.$link.' </a> ';

  }
  return $file;
}
add_filter( 'wp_handle_upload_prefilter', 'my_max_image_size' );

I've also tried with using $var and sprintf, echo, printr but nothing seems to work.

1 Answer 1

0

It's probable that HTML tags are being removed from output. You can test this by adding other HTML tags (ex: <strong>) and see if they are removed. If the bold text shows, it's possible then that bold text is permitted but not links (using wp_kses() or similar).

I backtracked the code quite a bit to see if I could find how/where the code was displayed, but did not find it quickly.

If HTML is being stripped in PHP, then the solution is to use JavaScript to add the link in.

2
  • Yes, that's what's happening - hence the reason for the question! Jun 2 at 8:08
  • You will not be able to add the link with PHP then: will need to do some JavaScript manipulation.
    – Caleb
    Jun 2 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.