zaza41rus
@zaza41rus

Как подключить скрипт в functions.php и он начал работать?

Есть код в functions.php который подгружает в модальном окне посты
// Post popUp

/* Регистрация скрипта functions.js */

add_action( 'wp_enqueue_scripts', 'theme_register_scripts', 1 );

function theme_register_scripts() {

  /** Register JavaScript Functions File */
  wp_register_script( 'functions-js', esc_url( trailingslashit( get_template_directory_uri() ) . 'js/functions.js' ), array( 'jquery' ), '1.0', true );

  /** Localize Scripts */
  $php_array = array( 'admin_ajax' => admin_url( 'admin-ajax.php' ) );
  wp_localize_script( 'functions-js', 'php_array', $php_array );

}

/** Enqueue Scripts. */
add_action( 'wp_enqueue_scripts', 'theme_enqueue_scripts' );
function theme_enqueue_scripts() {

  /** Enqueue JavaScript Functions File */
  wp_enqueue_script( 'functions-js' );

}

/* Ajax Post */
add_action( 'wp_ajax_theme_post_example', 'theme_post_example_init' );
add_action( 'wp_ajax_nopriv_theme_post_example', 'theme_post_example_init' );

function theme_post_example_init() {

/* Made Query */
$args = array( 'p' => $_POST['id'],'post_type' => array( 'post', 'page', 'track' ) );
$theme_post_query = new WP_Query( $args );
while( $theme_post_query->have_posts() ) : $theme_post_query->the_post();
?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
	<?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'has_post_thumbnail' );
	$url = $thumb['0']; ?>
	<div class="animation-fadeIn">
		<div id="post-div-pic0" style="overflow: hidden;">
			<div id="post-div-pic1" style="background-image: url(<?=$url?>); animation: fade-in .5s linear; @keyframes fade-in {0%{ opacity: 0; }100%{ opacity: 1;}}">
				<img src="<?=$url?>" width="0" height="0">
			</div>
		</div>
		<div id="posttex" style="animation: fade-in .5s linear; @keyframes fade-in {0% { opacity: 0; }100%{ opacity: 1;} };">
			<h2><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr( 'Permalink to %s' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
			<div class="entry-content"><?php the_content(); ?>
			</div><!-- end .entry-content -->
		</div>
	</div>
	<script src="http://inst:8888/wp-content/themes/inst/js/slick.min.js?ver=20151215"></script>
</div>
<?php
endwhile;
exit;
}

в этих постах есть карусель с изображениями/видео
скрипт

если его прописать так как в коде выше работает

но проблема в том что данную карусель использую не только в постах этих но и отдельно бывает

как прописать данный скрипт в functions.js чтоб он работал и в постах в модальном окне при и просто и чтоб вордпресс не грузил его по 2 раза отдельно для поста и отдельно для какого нить шаблона?

ща используется код выше и плюсом
wp_enqueue_script( 'slick', get_template_directory_uri() . '/js/slick.min.js', array(), '20151215', true );

все работает - но не думаю что это нормально )))
  • Вопрос задан
  • 325 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы