Support » Themes and Templates » Get current page name in header.php

  • handrjohnson

    (@handrjohnson)


    Is there a way to reduce this to

    <?php if (is_page('about')): ?>
    <script type="text/javascript">var page = "about";</script>
    <?php endif ?>
    
    <?php if (is_page('contact')): ?>
    <script type="text/javascript">var page = "contact";</script>
    <?php endif ?>
    
    <?php if (is_page('gallery')): ?>
    <script type="text/javascript">var page = "gallery";</script>
    <?php endif ?>

    <script type="text/javascript">var page = "<?php echo get_current_page() ?>";</script>

Viewing 2 replies - 1 through 2 (of 2 total)
  • Nerx

    (@nerx)

    Try to change the current HTML on the page you would like to reduce.

    Michael

    (@alchymyth)

    untested:

    <script type="text/javascript">var page = "<?php echo $post->post_title; ?>";</script>

    or $post->post_name for the slug

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get current page name in header.php’ is closed to new replies.