WordPress.org

Ready to get started?Download WordPress

Forums

Get current page name in header.php (3 posts)

  1. handrjohnson
    Member
    Posted 3 years ago #

    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>

  2. Nerx
    Member
    Posted 3 years ago #

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

  3. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    untested:

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

    or $post->post_name for the slug

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags