I
I
igor_solweb2020-08-05 16:24:22
WordPress
igor_solweb, 2020-08-05 16:24:22

How to display the desired script through a php condition for the desired Wordpress page?

Good afternoon!

I work with wordpress.
There is a task for a specific page (post) with id=25 to connect your script cutom-
scripts.js the theme is crooked and wp_footer( ) is inserted crookedly in the wrong place (not my site).
But you can connect it directly in the footer.php itself (because the scripts are already connected there). Here are just PHP I know quite a bit and do not have enough knowledge of how to correctly write the condition. I bring my code:

<script src="<?php bloginfo('template_url'); ?>/module/jquery/jquery.min.js"></script>
  <script src="<?php bloginfo('template_url'); ?>/module/formstyler/jquery.formstyler.min.js"></script>
  <script src="<?php bloginfo('template_url'); ?>/module/rangeslider/ion.rangeSlider.min.js"></script>
  <script src="<?php bloginfo('template_url'); ?>/module/owl-carousel/owl.carousel.min.js"></script>
  <script src="<?php bloginfo('template_url'); ?>/module/fancybox/jquery.fancybox.min.js"></script>
  <script src="<?php bloginfo('template_url'); ?>/module/maskedinput/jquery.mask.min.js"></script>
  <script src="<?php bloginfo('template_url'); ?>/scripts/main.js"></script>
  
        <?php
  $post_id = get_the_ID();

      if ($post_id = 25) {
      ?>
      <script src="<?php bloginfo('template_url'); ?>/scripts/custom-scripts.js"></script>
      <?php
      }

  ?>


But it still loads the desired script on all pages, tell me how to do it right, thanks in advance.
I will definitely mark the solution =)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
IvanMogilev, 2020-08-05
@igor_solweb

if ($post_id == 25) {, if it doesn't work print $post_id and see if it contains the required id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question