This is what it should be:
<img onclick="og_load();" style="cursor: pointer;" src="wp-content/uploads/2018/04/downloadnow1.png" alt="" width="455" height="116">
But it keeps changing in:
<img style="cursor: pointer;" src="/wp-content/uploads/2018/04/downloadnow1.png" alt="" width="455" height="116" />
I assume something has to be added in the functions.php but the solution is above my knowledge, anyone could lend me a hand?
Cheers.
Edit: Hmm I read slightly different questions but all stated it has some to do with the WP text editor.
And the code is to call a content locker of which the script I added to the head tag.
In a static site I already got it working but because the editor is keep changing the code it will not call the locker.
I tried this to remove the tag limitation
Method 1: Disable WordPress filtering of script tags
If you trust that your authors won’t get themselves into trouble, you can disable the blocking of script tags from within JavaScript. In wp-config.php within your root web directory, you’ll need to enable custom tags by adding the following line of code:
define( 'CUSTOM_TAGS', true );
Within your functions.php page, you can add the following code:
function add_scriptfilter( $string ) { global $allowedtags; $allowedtags['script'] = array( 'src' => array () ); return $string; } add_filter( 'pre_kses', 'add_scriptfilter' );
Unfortunately that gave this error:
Warning: in_array() expects parameter 2 to be array, null given in /home/a7480/public_html/wp-includes/kses.php on line 1416
And to clarify it's an image in a post that when clicked needs to call the content locker.
Update:
Ok this is weird, When I replace the image url in "inspect element" with
<img onclick="og_load();" style="cursor: pointer;" src="wp-content/uploads/2018/04/downloadnow1.png" alt="" width="455" height="116">
It does work...
Now to find out how to let it actually work.
Last Update: Sweet mother of God I finally got it to work, the only thing that sucks is if I switch to visual editor it strips the code.
onclick
by default. This behavior can be overridden using thetiny_mce_before_init
. You should be able to adapt this solution so that it targetsimg
tags rather than links.