0

So if i use the following in functions.php in the root off my child folder it works as supposed:

add_action( 'wp_enqueue_scripts', 'register_my_scripts');
add_action( 'wp_enqueue_scripts', 'checkboxCheckAll');
//register_scripts
function register_my_scripts(){

wp_register_script('checkboxCheckAll', get_stylesheet_directory_uri().'/Lib/dynamic-table/jsScripts/checkboxCheckAll.js');
}

//enqueue_scripts
function enqueue_my_scripts(){
wp_enqueue_script('checkboxCheckAll');
}

now i have a custom page with the following code:

<?php /* Template Name: vagter-flex */ ?>

<?php get_header(); ?>


    <div class="x-main full" role="main">

      <?php while ( have_posts() ) : the_post(); ?>

        <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
          <div class="entry-wrap">

            <?php x_get_view( 'global', '_content', 'the-content' ); ?>
            <?php require('Lib/dynamic-table/functions.php');?>
          </div>
        </article>

      <?php endwhile; ?>

    </div>


<?php get_footer(); ?>

now this page also loads a file called functions.php and if i try to enqueue the script with the same code as above its not working, there is no errors displayed and simply nothing happens?

and just to make it clear yes i am on the custom page when i try to use the script

2
  • where is the custom page template? if it is not in the theme root it might not be finding header.php which (should) call wp_head
    – majick
    Commented Jun 12, 2016 at 11:00
  • function enqueue_my_scripts() should be function checkboxCheckAll()
    – bravokeyl
    Commented Jun 12, 2016 at 11:06

1 Answer 1

1

That isn't how functions.php works in WordPress.

The functions.php in your theme root directory is loaded into WordPress environment by default as long as your theme is activated. It's used as a plugin to add features and functionality of your theme to WordPress. You should take a look at theme functions and including css & javascript for more info.

Besides that, the wp_enqueue_scripts hook is fired inside the get_header() which happens before you can require('Lib/dynamic-table/functions.php').

You can fix that by require('Lib/dynamic-table/functions.php') inside the functions.php in theme root directory.

2
  • thanks for the informative answer if i could vote it up i would :)
    – Alexander
    Commented Jun 12, 2016 at 13:54
  • @Alexander No problem. Glad I could help ;-)
    – Minh Tri
    Commented Jun 12, 2016 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.