Skip Navigation

[Resolved] Need to remover Jquery code in front-end

This support ticket is created 4 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

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 1.30 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 6 replies, has 2 voices.

Last updated by poulP 4 years, 6 months ago.

Assisted by: Christian Cox.

Author
Posts
#1628761

Hi,
I try to make a wp-site without using Jquery (for not logged in users). I have a simpel design using Astra theme, so
for the normal visitor I focus on loading fast. I have deregistered Jquery, but I get js-error because Toolset put some Jquery code in the page. I know that the code Toolset put in is related to extra Css in content templates and views, but I use very little extra css and can put that in in another way. So can you tell me how to avoid the divs and Jquery related to this (see below)?
Here is the code I would like to get rid of:

<div id="views-extra-css-ie7" style="display:none;" aria-hidden="true">
<!--[if IE 7]><style>
.wpv-pagination { *zoom: 1; }
</style><![endif]-->
</div>

<div id="ct-extra-css" style="display:none;" aria-hidden="true">
/* ----------------------------------------- */
/* Content Template: -start*/
/* ----------------------------------------- */

/* ----------------------------------------- */
/* Content Template: - end */
/* ----------------------------------------- */
</div>

<script type="text/javascript">
jQuery( document ).ready( function( $ ) {
$( 'head' ).append( '<style>' + $( "#ct-extra-css" ).text() + '</style>' );
$( "#ct-extra-css" ).remove();});
</script>
<script type="text/javascript">
jQuery( document ).ready( function( $ ) {
var extra_css = $( "#views-extra-css" ) ? $( "#views-extra-css" ).text() : null; if( extra_css ) { $( 'head' ).append( '<style>' + extra_css + '</style>' );
$( "#views-extra-css" ).remove(); }
if( $( "#views-extra-css-ie7" ).length > 0 ) { $( 'head' ).append( $( "#views-extra-css-ie7" ).html() );
$( "#views-extra-css-ie7" ).remove(); }});
</script>

#1629333

Hi, for technical reasons, in the current software, sometimes it is not possible to know when specific templates will be enqueued on specific pages, so the stylesheet code is written into the page source using these hidden divs and transferred to the page header as needed once the content has loaded. Toolset requires jQuery and unfortunately there is not currently a simple workaround available to dequeue this code. We suggest you do not dequeue jQuery for this reason.

If you'd like to see this process improved by removing the jQuery requirement here, I encourage you to submit your request in our feature request form here: https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset

Our developers will evaluate your request and determine whether or not it is technically possible to eliminate the need for jQuery and extra divs here.

#1629371

Hi,
I dont nessasary need a simple workaround. But if there is no solution with using functions.php, then maybe you could tell what/which files are responsible for generating/inserting the Jquery and divs?. I think option to remove should be possible - what if I would like to make amp page?

#1629607

It does seem like a minor change, but unfortunately I cannot recommend making changes to core plugin files because they could have unexpected consequences that break your site. Without our developers testing those changes, I can't guarantee the plugins would continue to work correctly. The plugins aren't designed to work this way, so changes to enable that must be implemented as a new feature. Our developers should be involved to make sure this is working correctly, which is why the feature request form is the best place to request this type of change.

As far as making an AMP version of the site, keep in mind that JavaScript is required for full Toolset functionality. Any system that strips out JavaScript capabilities, or prevents loading JavaScript files, is inherently incompatible with Toolset as a whole. I'm not very familiar with AMP, but if you want to disable Toolset plugins on specific URLs/pages of the site, then you might be able to use some custom code or a 3rd-party plugin to accomplish that. For example, this post shows how to create a must-use plugin that activates or deactivates plugins on-the-fly: https://kinsta.com/blog/disable-wordpress-plugins-loading/ It might be useful as a starting point for achieving something like you have described, but again this is a type of customization that isn't supported here in the forums.

A few related posts and comments in forums and blog posts:
https://toolset.com/forums/topic/is-there-a-way-to-only-load-toolset-plugin-js-on-specified-pages/
https://toolset.com/forums/topic/change-content-template-via-parameters/ (this ticket was never completed but you can find out more about changing content templates programmatically here: https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_force_template)
https://toolset.com/forums/topic/load-different-layouts-via-php-conditionally/
https://toolset.com/2019/11/toolset-views-becoming-toolset-blocks/#comment-465187

#1629973

Hi,
ok I agree that its maybe best not to begin to change core files.
I looked a little on the other options you write about.
I just have a final question: If I change content templates programmatically, according to the guides/link you have provided, Will the mentioned code (Jquery and divs) still be applied in the frontend/page, for eample if I make something similar to your example:

//Show a specific Content Template applied to a given post for not logged in visitors and in every place where this post appears:
add_filter( 'wpv_filter_force_template', 'prefix_fixed_content_for_visitors', 99, 3 );
  
function prefix_fixed_content_for_visitors( $template_selected, $id, $kind ) {
    if ( !is_user_logged_in() && $id == 345 ) { // if the user is not logged in and is trying to view the post with ID 345
        $template_selected = 123; // assign a fixed Content Template with ID 123 that contains a static text
    }
    return $template_selected;
}
#1631225

Will the mentioned code (Jquery and divs) still be applied in the frontend/page, for eample if I make something similar to your example:
Yes, the jQuery and divs you described will still be applied in the frontend/page even if you choose to apply different Content Templates programmatically.

#1631395

My issue is resolved now. Thank you!