• Why following code doesn’t work?

    if ( is_page_template( 'frontpage1.php' ) ) {
        function enqueue_xxxx() {
        ?>
        <script type="text/javascript">
        .....
        </script>
        <?php
        }
        add_action('wp_footer', 'enqueue_xxxx');
        }
    • This topic was modified 8 years, 6 months ago by m1000.
    • This topic was modified 8 years, 6 months ago by Steven Stern (sterndata). Reason: put code in code tags
Viewing 9 replies - 1 through 9 (of 9 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    In what way is it not working?

    Thread Starter m1000

    (@m1000)

    It doesn’t display script in footer, when I remove
    if ( is_page_template( 'frontpage1.php' ) ) { }
    condition then it works but I want to didplay it on frontpage1.php temmplate.

    • This reply was modified 8 years, 6 months ago by m1000.
    • This reply was modified 8 years, 6 months ago by m1000.
    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    Use the plugin “show current template” to double check on what is the “master” template for rendering a page.

    Thread Starter m1000

    (@m1000)

    It’s showing Template: frontpage1.php on toolbal

    Thread Starter m1000

    (@m1000)

    BTW I use this code in functions.php

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    OK, just checking for low hanging fruit. And that template is in the top level of the theme directory?

    OH, just re-looked at your code. Remove the function def from the conditional — it should be like this:

    function enqueue_xxxx() {
       if ( is_page_template( 'frontpage1.php' ) ) {
          ?>
            <script type="text/javascript">
            .....
            </script>
            <?php
        }
     }   
        
    add_action('wp_footer', 'enqueue_xxxx');
    Thread Starter m1000

    (@m1000)

    Thanks but I used this code and it’s not working

    function enqueue_xxxx() {
       if ( is_page_template( 'frontpage1.php' ) ) { ?>
        CODE
      <?php
        }
     }
    
    add_action('wp_footer', 'enqueue_xxxx');
    • This reply was modified 8 years, 6 months ago by m1000.
    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    Let’s try an experiment:

    function enqueue_xxxx() {
      echo '<!-- Page template is ' . get_template_slug() . ' -->';
    
     }
    
    add_action('wp_footer', 'enqueue_xxxx');

    run that and see what appears in the page source

    Thread Starter m1000

    (@m1000)

    It’s breaking the page
    This code also breaking the page after Page template is

    function enqueue_xxxx() { ?>
      Page template is <?php echo get_template_slug();
    
    }
    add_action('wp_footer', 'enqueue_xxxx');
    • This reply was modified 8 years, 6 months ago by m1000.
Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘is_page_template() is not working’ is closed to new replies.