• Resolved NorfolkUK

    (@norfolkpete)


    Hi there,

    Seen this asked before but more from what I could tell it was for JS.

    New at using Code Snippets, used to child themes ??

    Is there a way of running a CSS Snippet to a specific page, I guess by number post=90285

    Worth an ask. Many thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    Absolutely. Here’s an example:

    add_action( 'wp_head', function () {
        if ( ! is_page( 90285 ) ) {
            return;
        } ?>
        <script>
    
        /* CSS code here */
    
        </script>
        <?php
    } );
    Thread Starter NorfolkUK

    (@norfolkpete)

    Hi there Shea,

    Many thanks for letting me know, that’s great.
    One final ask…what if I have a few page numbers? Say 4?

    Thank you.

    add_action( 'wp_head', function () {
        global $wp_query;
    
        $page_ids = array( 123, 456, 789, 1011 );
    
        if ( ! in_array( $wp_query->post->ID, $page_ids, true ) ) {
            return;
        } ?>
        <script>
    
        /* CSS code here */
    
        </script>
        <?php
    } );
    Plugin Author Shea Bunge

    (@bungeshea)

    Thanks for the example Alexandre!

    Thread Starter NorfolkUK

    (@norfolkpete)

    Thank you very much for this Alexandre, appreciate it ??

    It would be great to have this option built into Code Snippets.

    Plugin Author Shea Bunge

    (@bungeshea)

    It’s something we are definitely considering in the future @norfolkpete ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Target a Page’ is closed to new replies.