Skip Navigation

[Resuelto] A field that contains a script will not display unless you are logged in

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 6.75 hours from now. Thank you for your understanding.

This topic contains 4 respuestas, has 2 mensajes.

Last updated by Tim Elliott hace 2 años, 3 meses.

Assigned support staff: Nigel.

Autor
Mensajes
#1316983

I have a custom multi-line field that contains a script for a certain post:

<script type="text/javascript" src="<em><u>hidden link</u></em>"></script>

I'm displaying it in a content template using:

[types field='casino-cta-script' output='raw'][/types]

When I'm logged in to admin and I view the post on the frontend the banner is displayed as expected.
When I'm not logged in and I view the post the banner is not displayed. There is no code being shown.

If I change the field value to some text it does display on the frontend, it's just the code that doesn't get rendered.
I've also tried it with a single line field and the same thing happens.

Link to a page where the issue can be seen: hidden link
Just below the "Ratings" section is a grey bar where the banner should appear.

#1317061

Nigel
Supporter

Languages: Inglés (English ) Español (Español )

Timezone: Europe/London (GMT+00:00)

Hi Tim

It seems to be a problem with the script you are calling rather than with the Types custom field.

I set up a local test to confirm that script tags work okay inside a multiline field whether logged in or not (with a simple text alert) and it did.

So, following your example, I added a slightly more complex case where I was src-ing an external script, but I got the same result.

I linked to some random library available on a CDN and used it and it worked whether logged-in as an admin or visiting the page as a guest.

Concretely, this is what I added to my multiline text field:

<script type="text/javascript" src="<em><u>hidden link</u></em>"></script>

<script type="text/javascript">

adblockDetect( function(adblockDetected) {

    if (adblockDetected) {
        console.log('Ad blocker is detected');
    } else {
        console.log('Ad blocker is not detected');
    }

    }, {
    testInterval: 40,
    testRuns: 5
    }
);

</script>

The first script tag pulls in an external script, the second script tag uses it, sending messages to the console.

And it worked, as I say, in either scenario.

So the problem appears to be particular to your script.

I suggest you try to reproduce my test to confirm the same. If you get different results then we'd need to try testing for conflicts with other plugins or your theme, etc.

#1317089

Hi Nigel

Thanks for testing. I think it's nothing to do with Toolset now, so sorry to have taken up your time. I believe it's the caching plugin causing the problem.

Thanks for your help.
Tim

#1317101

Nigel
Supporter

Languages: Inglés (English ) Español (Español )

Timezone: Europe/London (GMT+00:00)

Sure, no problem.

If that is the case then please feel free to close.

#1317103

My issue is resolved now. Thank you!