简体   繁体   中英

Wordpress wp_enqueue_scripts() triggers 500 Internal Server Error

I'm editing a functions.php file in a child version of a WordPress theme in order to load a custom javascript filmScript.js , which exists, but is currently empty. If I comment out line 10

wp_enqueue_scripts( 'myVideo', get_stylesheet_directory_uri() . '/assets/js/filmScript.js', array('jquery'), '1.0.0', false );

everything works: echo statements log to the console, the page loads, etc. However, when the line is being read the page breaks and throws a 500 Internal Server Error . Here's the entire functions.php:

<?php

add_action( 'wp_enqueue_scripts', 'video_bg', 10);
add_action( 'after_setup_theme', 'post_theme_setup' );

if ( !function_exists( 'post_theme_setup' )):
function post_theme_setup(){

    function video_bg() {
        wp_enqueue_scripts( 'myVideo', get_stylesheet_directory_uri() . '/assets/js/filmScript.js', array('jquery'), '1.0.0', false );
        echo '<script>console.log("Script added?")</script>';
    }

    add_action( 'wp_enqueue_scripts', 'video_bg', 10);
    echo '<script>console.log("Action added")</script>';

}
endif;

Any thoughts? Thanks!

Please use get_template_directory_uri() instead of get_stylesheet_directory_uri() . It can't work in enqueue scripts because it's for enqueueing stylesheets.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM