Conditional string comparison failing for basename/slug

I am trying to display a particular block of html for one page in particular. I have created a conditional statement that compares the basename of the page to my string.

?php if ( has_tag( 'Sponsor' )  basename( get_permalink() != 'sponsor-one') ) : // show sponsor's footer if applicable ?
div class="sponsor-footer ?php echo basename( get_permalink() ); ?"
    pOur text here/p
/div
?php elseif ( has_tag( 'Sponsor' )  basename( get_permalink() == 'sponsor-one') ) : // show sponsor one's footer if applicable ?
div class="sponsor-footer ?php echo basename( get_permalink() ); ?"
    pOur other text here/p
/div
?php endif; ?

It always outputs the first block of code even when the slug is "sponsor-one".

If I var_dump( basename( get_permalink() ) ); I get string(11) "sponsor-one", so why is it saying that the basename is not equal to "sponsor-one"?

Topic comparison php templates Wordpress

Category Web


The 2nd part of the condition seems wrong

basename( get_permalink() != 'sponsor-one') should be basename( get_permalink() ) != 'sponsor-one'

Please check where the parenthesis ends. Also in your code if that is the only condition, then you can have an else statement instead of having another elseif.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.