I want to add some "dependencies" (Bootstrap and CanvasJS) to my WordPress website. Therefore I wrote such code in functions.php file:

function basic_enqueue_style()
    wp_enqueue_script('popper', 'https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js', ['jquery']);
    wp_enqueue_script('bootstrap', 'https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js', ['jquery', 'popper']);
    wp_enqueue_style('bootstrap', 'https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css');

    /*Personal CSS*/
    wp_enqueue_style('main', get_template_directory_uri() . '/css/main.css');

    wp_enqueue_script('canvasjs', get_template_directory_uri() . '/js/canvasjs.min.js');

add_action('wp_enqueue_scripts', 'basic_enqueue_style');

As "dependencies" they should be loaded from header not footer thus I did not indicated $in footer as true (default false) parameter.

Documentation says:

wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer);

The error information I get after adding "dependencies":

enter image description here

Shall I change something in index.php file? Which now looks like this:

<?php get_header(); ?>

<?php if (is_user_logged_in()): ?>
    <?php  $expensesFormPage = get_page_by_title('formularz wydatkow'); ?>
    <?php  wp_redirect(get_permalink($expensesFormPage->ID)); ?>
<?php else: ?>
    <a href="<?php echo wp_registration_url(); ?>">Zarejestruj sie!</a>
    <?php wp_login_form(); ?>
<?php endif; ?>

<?php get_footer(); ?>

Many thanks for any help!!

  • 1
    wp_redirect won’t work after output has started
    – Milo
    Jun 27, 2018 at 21:43
  • What do you mean exacly? Jun 27, 2018 at 21:47
  • @AdrianJelonek that you can’t do redirect after any html was already printed. So I your case, you can’t do redirect after printing header... Jun 27, 2018 at 22:11
  • Ok. So why does it work (I mean redirection works fine) when I delete wp_enqueue_script dependencies from functions.php and leaves wp_enqueue_style dependencies? Jun 27, 2018 at 22:15

1 Answer 1


OK. Thanks to @Milo and @Krzysiek Dróżdż I changed the code in index.html file and it works now.

I put get_header() after redirection method.

<?php if (is_user_logged_in()): ?>
    <?php $expensesFormPage = get_page_by_title('formularz wydatkow'); ?>
    <?php wp_redirect(get_permalink($expensesFormPage->ID)); ?>
<?php else: ?>
    <?php get_header(); ?>
    <h1>Aby korzystać z aplikacji musisz się zarejestrować.</h1>
    <a href="<?php echo wp_registration_url(); ?>">Zarejestruj się!</a>
    <?php wp_login_form(); ?>
<?php endif; ?>

<?php get_footer(); ?>

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.