0

I am making a shortcode plugin that sends a variable to a JS script. The CSS is not being applied to the page with the shortcode or any other page. Any idea to fix this, please? The CSS link does exist in the page source when I checked.

        add_action( 'wp_enqueue_scripts', 'register_scripts' );


        function register_scripts() {
        wp_register_script( 'NN', plugins_url( 'main.js', __FILE__ ),
            'jquery', 0.01, true );
        wp_register_style( 'namespace', plugins_url( 'main.css', __FILE__ ),
            'css', 0.03, true );
        }

        add_shortcode( 'Now', 'my_handle_shortcode' );


        add_action( 'wp_enqueue_scripts', 'load_javascript' );


        function load_javascript() {        
        $NN=1;

        wp_localize_script( 'NN', 'NN', array( 'text' => $NN ) );

        function my_handle_shortcode() {

        return '
        <div id="inner">
        <span ></span>
        </div>
        ';
        wp_enqueue_script( 'NN' );
        wp_enqueue_style('namespace');  

        }

        } //end load js -->
  • Why is my_handle_shortcode() inside load_javascript()? – Jacob Peattie Mar 14 '18 at 12:21
  • Are you trying to load css to a specific page? Why not just enqueue it for that page using a conditional? – Nathaniel Flick Mar 18 '18 at 2:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.