Hi Nickth!
This is super weird. First of all, our plugin’s not the one setting the onclick
attribute; that probably your theme’s work. So, if it adds spaces in the assignment operator, it’s its doing, not ours. And, by the way, that’s not a problem. The onclick
action works regardless of these spaces being present or not.
Second, the problem with a featured image not being inserted. My guess is, your theme’s using a couple of functions (get_post_thumbnail_id
and wp_get_attachment_image_src
) for retrieving the featured image’s URL. Since the image is not in the media library, those two functions don’t work.
In order to overcome that issue, we need to know where the functions are used and modify the code so that it uses the external featured image, if set. Your theme will probably look similar to this:
$image_id = get_post_thumbnail_id( get_the_ID() );
$image_thumb = wp_get_attachment_image_src( get_the_ID(), 'full', true );
?>
<div onclick="..." style="background:url(<?php echo $image_thumb[0]; ?>)" ... />
See? We retrieve an image ID (it doesn’t exist, because the image wasn’t uploaded to your media library; it’s external) and then we try to obtain its URL, so that we can add it in the div
tag.
Instead, you need to change that fragment so that it looks like this:
<?php
$image_id = get_post_thumbnail_id( get_the_ID() );
$image_thumb = wp_get_attachment_image_src( get_the_ID(), 'full', true );
if ( function_exists( 'uses_nelioefi' ) &&
uses_nelioefi( get_the_ID() ) {
$image_thumb = array( nelioefi_get_thumbnail_src( get_the_ID() ) );
}
<div onclick="..." style="background:url(<?php echo $image_thumb[0]; ?>)" ... />
Now, right before we use $image_thumb
(which is probably empty), we check if the current post has an external featured image and, if it does, we use it.
I hope this helps!
Best,