Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1466216

    Hi,
    i need to add this code to the <head> section for specific pages only:

    <head>
      <script type="module" src="./mapplic.js"></script>
      <link rel="stylesheet" href="./mapplic.css">
    </head>

    How can i do that?

    kind regards
    Jak

    • This topic was modified 3 weeks, 2 days ago by Jak73.
    • This topic was modified 3 weeks, 2 days ago by Jak73.
    • This topic was modified 3 weeks, 2 days ago by Jak73.
    • This topic was modified 3 weeks, 2 days ago by Jak73.
    #1466240

    Hey Jak73,
    Try adding this code to the end of your child theme functions.php file in Appearance ▸ Editor and change the page IDs in the array to the ones you want to use, then add your snippet

    function my_code() {
    if(is_page( array(206, 591, 597) ) )
        {
    ?>
    //Put Your Code Here
    <?php
     }
    }
    add_action( 'wp_head', 'my_code' );

    Best regards,
    Mike

    #1466241

    Hi Mike,
    where do i add the page id (489)?
    How ca i add more then one page (for example page 500, 501,502 too)?

    Like this:

    function my_code() {
    if(is_page( array(489, 501, 502) ) )
        {
    ?>
    <script type="module" src="./mapplic.js"></script>
    <link rel="stylesheet" href="./mapplic.css">
    <?php
     }
    }
    add_action( 'wp_head', 'my_code' );

    ?

    kind regards
    Jak

    • This reply was modified 3 weeks, 2 days ago by Jak73.
    #1466268

    Hi,

    Thank you for the update.

    Yes, the code and the placement of the argument or array values in the conditional function looks correct. You can add more page IDs if needed. Here’s the formatted version:

    function my_code() {
        if ( is_page( array( 489, 501, 502, 123 ) ) ) {
            ?>
            <script type="module" src="./mapplic.js"></script>
             	<link rel="stylesheet" href="./mapplic.css">
            <?php
        }
    }
    add_action( 'wp_head', 'my_code' );
    

    Best regards,
    Ismael

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.