0

I'm trying to use a script called show_post.js on my Wordpress site. I've successfully loaded it directly in header.php:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script type="text/javascript" src="wp-content/themes/tutorial_theme/scripts/show_post.js"></script>

However, when I'm trying to do it via functions.php and wp_enqueue_script it won't work. Here is my functions.php file:

<?php function wpdocs_scripts_method() {
   wp_enqueue_script('show_p', '/wp-content/themes/tutorial_theme/scripts/show_post.js', array( 'jquery' ));
}
add_action( 'wp_enqueue_scripts', 'wpdocs_scripts_method' );
?>

What am I doing wrong here?

1
  • have you added wp_head() function before </head> in header.php file?and which theme are you working?child theme or parent theme? Commented Apr 16, 2016 at 7:38

2 Answers 2

1

Add Script like

wp_enqueue_script('show_p',get_template_directory_uri().'/scripts/show_post.js', array( 'jquery' ));
Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

function theme_enqueue_scripts() {
wp_register_script("show_p", get_template_directory_uri() . '/scripts/show_post.js', array('jquery'));

   wp_enqueue_script('show_p');
}
add_action('wp_enqueue_scripts', 'theme_enqueue_scripts');

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.