file ); wp_register_style( 'mortgage-matic', $url . 'assets/css/calculator.css', array(), self::VERSION ); wp_register_script( 'mortgage-matic-math', $url . 'assets/js/math.js', array(), self::VERSION, true ); wp_register_script( 'mortgage-matic', $url . 'assets/js/calculator.js', array( 'mortgage-matic-math', 'wp-i18n' ), self::VERSION, true ); wp_set_script_translations( 'mortgage-matic', 'mortgage-matic', dirname( $this->file ) . '/languages' ); $shortcode = new CalculatorShortcode( dirname( $this->file ) ); add_shortcode( 'mortgage_matic', array( $shortcode, 'render' ) ); add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_page_assets' ) ); } /** Load styles in the document head when the page contains our shortcode. */ public function enqueue_page_assets(): void { $post = get_post(); if ( $post instanceof \WP_Post && has_shortcode( $post->post_content, 'mortgage_matic' ) ) { wp_enqueue_style( 'mortgage-matic' ); wp_enqueue_script( 'mortgage-matic' ); } } }