Site logo

[Support request] Adding a bunch of javascript calculators

Home Forums Support [Support request] Adding a bunch of javascript calculators

Home Forums Support Adding a bunch of javascript calculators

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #2535998
    Robert

    I have a few javascript calculators that I’ve added using elements. I create the hook elements and set them to load on a specific page. Then on that page I add the html block for my calculator.

    However, we’d like to add dozens of these calculators. Is there a way to do this by uploading all the files via FTP? I can upload the files, but then how would I make sure the files load on specific pages?

    #2536188
    Fernando
    Customer Support

    Hi Robert,

    Yes, there’s a way. You can create the file and enqueue it. See here for an example: https://developer.wordpress.org/reference/functions/wp_enqueue_script/#comment-274

    To enqueue a file to a specific page, you just need a conditional statement.

    An example where 123 is the ID of the page:

    function wpdocs_theme_name_scripts() {
        is_page( 123 ){
    	wp_enqueue_style( 'style-name', get_stylesheet_uri() );
    	wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/example.js', array(), '1.0.0', true );
        }
    }
    add_action( 'wp_enqueue_scripts', 'wpdocs_theme_name_scripts' );
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.