Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 946533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:55:59+00:00 2026-05-15T22:55:59+00:00

Is there a php or javascript code that can detect the current user’s page

  • 0

Is there a php or javascript code that can detect the current user’s page and then add <a class="active"> to an item in a ul (my menu). I include my menu in my pages with PHP include so making change is easy; I only have to edit it once. But, with that method, I can’t individually set each page to have a class="active". How can I do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T22:56:00+00:00Added an answer on May 15, 2026 at 10:56 pm

    If I’m understanding your question correctly, what I usually do is set a variable before I include the header, like

    $current = "home";
    

    And then in the header I’d have an if statement in each link

    <a href="/home" <?php if ( $current == "home" ) { echo "class='active'" } ?>>Home</a>
    

    Could be ways to improve it, but it’s simple if your menu isn’t too big.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 539k
  • Answers 539k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I'm assuming that you're just a getting a blank screen… May 17, 2026 at 2:24 am
  • Editorial Team
    Editorial Team added an answer I found an alternative using PECL runkit_lint_file(). It does the… May 17, 2026 at 2:24 am
  • Editorial Team
    Editorial Team added an answer This is an URI-encoded string: require 'uri' #=> true s… May 17, 2026 at 2:24 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I've found that loading the same javascript file twice or more (via PHP) can
I am looking for some code that will return me values if the user
I have a PHP code that will return a image. the link is given
I'm trying to programmatically close a Facebox modal with JavaScript code that's called within
I have a page where I am using a PHP while loop to echo
I'm trying to make a webpage that allows the uploading of multiple files at
I'm kind of a newbie with PHP so please bear with me. I would
I have a Web server that updates its data once per minute, and want
this is a general form code <form name=search_form action= method=POST> <input type=text name=search_text> <input
I have so far been a dedicated Wordpress user, but have been researching other

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.