Answer the question
In order to leave comments, you need to log in
How to connect your own script inside each entry?
Hello.
I am new to WordPress, so I don’t know how to implement the following correctly:
there are records on the site, each will have its own unique json file and one script that will load this file using ajax.
Where can I store these files and where should I write the path?
The site has the Advanced Custom Fields plugin installed, if it helps in this task.
Answer the question
In order to leave comments, you need to log in
Option 1
Advanced Custom Fields will do just fine in this situation. You can create a custom field that will be displayed in any part of the post content. Each post in the admin panel will have a metabox with an input field. Write there the code that you need to display in the front and voila.
Option 2
If it is more convenient for you to configure everything not in the admin panel, but write code in files. Then you can use the functions.php of your theme to register the connection of scripts for specific posts, below is an example:
add_action( 'wp', function () {
if ( is_single( 12 ) ) { //проверка идентификатора поста
// какой-либо код
}
} );
wp_enqueue_script('newscript', get_template_directory_uri() . '/js/custom_script.js');
wp_enqueue_script('newscript', get_stylesheet_directory_uri() . '/js/custom_script.js');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question