Home > database >  Add css class to html element using php in wordpress
Add css class to html element using php in wordpress

Time:06-04

I'm having a problem with why this code is not working.

<li><?php if( get_the_archive_title() == "1 Bedroom House Plan") { echo ''; } ?><a  href="#">1</a></li> 

All I want is if the archive page title is equal to the string on the right to echo the CSS class of "active-tag", I'm using WordPress here!

Thanks again :)

CodePudding user response:

Try to add like below:

<li <?php if( get_the_archive_title() == "1 Bedroom House Plan") { echo ''; } ?>><a  href="#">1</a></li>

CodePudding user response:

you just misplaced your php code :

<li> <?php if( get_the_archive_title() == "1 Bedroom House Plan") { echo ''; } ?>  <a  href="#">1</a></li> 

to

<li <?php if( get_the_archive_title() == "1 Bedroom House Plan") { echo ''; } ?>  
 >
    <a  href="#">1</a>
</li> 
  • Related