JavaScript How to Link a Script In WordPress link script in wordpress

My script doesn't work in Wordpress. I'm trying to convert my HTML page into a Wordpress Theme.. Ive got the CSS linked..

<link type="text/css" rel="stylesheet" target='_blank' href="<?php bloginfo('template_directory'); ?>/min/mycss.css" />     

but my script doesn't connect..

<script type="text/javascript" src="min/myjs.js"></script>

i tried the same , using the <?php bloginfo('template_directory'); ?>

<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/min/myjs.js"></script>

Help?

Answer:1

Don't include scripts and stylesheets this way. Use wp_enqueue_scripts. Assuming this is a custom theme, add the code to the functions.php file.

add_action( 'wp_enqueue_scripts', 'theme_scripts_styles' );

function theme_scripts_styles() {

  // Enqueue scripts and styles here

}

In this function use wp_enqueue_script and wp_enqueue_style to queue the files (should be obvious which to use based on the file type!)

Also bloginfo( 'template_directory' ) is not best practice.

Use get_stylesheet_directory_uri(), or get_template_directory_uri() for parent themes. You can drop the _uri part to get the server paths.

So all together it looks something like

add_action( 'wp_enqueue_scripts', 'theme_scripts_styles' );

function theme_scripts_styles() {

  wp_enqueue_style( 'my-styles', get_stylesheet_directory_uri() . '/min/mycss.css', array(), '1.0', 'all' );
  wp_enqueue_script( 'my-scripts', get_stylesheet_directory_uri() . '/min/myjs.js', array(), '1.0', true );

}

Be sure to read the Codex on the enqueue functions so you know what all the parameters do.

Answer:2

Orchestrate has a client for NodeJS. It is based on promises so I should define a function then and a function fail. The first should be triggered when the request is successful and the second one ...

Orchestrate has a client for NodeJS. It is based on promises so I should define a function then and a function fail. The first should be triggered when the request is successful and the second one ...

I'm working on an EM to PX converter. Basically you paste in your code in the "PX" textarea, and then the same code will appear in the "EM" textarea with em values. It kinda works, but doesn't ...

I'm working on an EM to PX converter. Basically you paste in your code in the "PX" textarea, and then the same code will appear in the "EM" textarea with em values. It kinda works, but doesn't ...

  1. regexp g flag
  2. regex g flag
  3. regex g flag javascript
  4. javascript regexp g flag
  5. js regexp g flag

How to append &nbsp; to the end of the last tag with jQuery? For example, my html would be something like this: <div> <p>line1</p> <p>line2</p> </div&...

How to append &nbsp; to the end of the last tag with jQuery? For example, my html would be something like this: <div> <p>line1</p> <p>line2</p> </div&...

  1. append python
  2. append definition
  3. append to list python
  4. append meaning
  5. append to dictionary python
  6. append dataframe pandas
  7. append to numpy array
  8. append to string python
  9. append to array javascript
  10. append javascript
  11. append to array python
  12. append jquery
  13. append to file python
  14. append in r
  15. append row to dataframe
  16. append two dataframes pandas
  17. append to list r
  18. append matlab
  19. append to tuple python
  20. append query access

I have a series of nested Ajax requests to external APIs, which is very ugly but it was the only way I could figure out how to make calls in a specified order with each call utilizing some values ...

I have a series of nested Ajax requests to external APIs, which is very ugly but it was the only way I could figure out how to make calls in a specified order with each call utilizing some values ...

  1. javascript global variables across files
  2. javascript global variables in function
  3. javascript global variables bad
  4. javascript global variables best practice
  5. javascript global variables not working
  6. javascript global variables
  7. javascript global variables naming convention
  8. javascript global variables between files
  9. javascript global variables window
  10. javascript global variables bad practice
  11. javascript global variables multiple files
  12. javascript global variables across pages
  13. javascript global variables in class
  14. javascript global variables security
  15. javascript global variables alternative
  16. javascript global variables between script tags
  17. javascript global variables in html
  18. javascript global variables file
  19. javascript global variables node.js
  20. javascript global variables in module