• Resolved dangleraction

    (@dangleraction)


    Hello,

    I have never had this problem before until I forced myself to use wp_enqueue_scripts. I think it’s a really cool way of doing things, by the way. I’m a web designer and beginner at java programming.

    My issue is just what the title says: Blank pages on my whole website, including the Dashboard. When the site does work, I see the blank page again whenever updating pages, configuring plugins, etc. It always crashes when “&_wpnonce=” is affixed the the end of my url.

    When the parent theme is active, my Dashboard and all functions work fine, except my WP Admin bar is not showing on the front end. One problem at a time though.

    My question is; What is the best way to arrange the wp_enqueue function to add specific scripts & stylesheets to specific pages?

    I will share what my functions.php looks like in another comment, but for right now, can you tell me if this a good way to approach what I want to do?

    <?php
    if (!is_admin()) {
        add_action( 'wp_enqueue_scripts', 'miosa_theme_scripts' );
        function miosa_theme_scripts() {
                if ( is_page_template('page-slider.php') ) {
                    wp_register_script('...');
                    wp_register_script('...');
                    wp_register_script('...');
                    wp_enqueue_script('modernizr');
                    wp_enqueue_script('slider-jquery');
                    wp_enqueue_script('slider-config');
                }
                elseif ( is_page_template('page-photo.php') ) {
                    wp_register_script('...') );
                    wp_register_script('...') );
                    wp_enqueue_script('isotope-jquery');
                    wp_enqueue_script('isotope-config');
                }
        }
    }

    That is a generalized version for my javascript. There is another one for my stylesheets and they all have a unique $handle

    I am using the (!is_admin) condition because I thought these scripts were causing my WP Dashboard to be blank. It could be something else? I have no idea. But between this and my browser cache and server cache, this website development is taking a lot longer than I wanted it to. I would really appreciate to hear other peoples’ advise because this is the first time I’m using the wp_enqueue_scripts constructor.

    Thanks,
    Rick

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Hi Rick, sorry for the slow response.

    While there is room for improvement, your basic structure is fine in theory, it should work if all the details are addressed correctly. Blank screens are usually due to PHP errors and not javascript errors. Define WP_DEBUG in wp-config.php as true to see what the PHP errors actually are, they can often be a simple silly oversight causing major malfunction.

    Now the improvements. No need for if (!is_admin()) because ‘wp_enqueue_scripts’ will never fire for admin pages, there is a different action for back end pages which you must use for back end scripts. ‘wp_enqueue_scripts’ is only for front end scripts.

    While it doesn’t hurt anything, you don’t need to register scripts if you are only going to enqueue it on the next line and never refer to it again. Simply supply the appropriate data to wp_enqueue_script() that you would have used to register. If you need to refer to the script in other locations, such as as a dependency, then you do register the script in order to assign a handle with which you can reference the script in multiple places.

    The first step in debugging enqueued script issues is to check the page source to see if the script is referenced at all, and if so, that the path is correct. Then check the parameters carefully for errors. Be sure the dependency parameter is an array, even for a single dependency.

    Good luck!

    Thread Starter dangleraction

    (@dangleraction)

    Hey bcworkz, a late reply is better than no reply! Thanks.

    I actually stumbled upon the WP_DEBUG feature from an online article a couple hours later. And I found the problem. My problem was I added separate <?php ?> tags for each of my functions. That made me feel kind of dumb, but it also made all my frustration and uneasiness go away. I’m really happy to know about the debug feature now. BTW, I thought I had posted on my thread that night but it must’ve never went through.

    And it’s good to know that I don’t have to add wp_enqueue_scripts afterwards. That will clean it up a lot more. Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Blank admin dashboard. Am I using wp_enqueue correctly on my child theme?’ is closed to new replies.