So I’m using the Advanced Custom Fields plugin. I want to be able to select different headers.
I’m able to echo the field name just fine, using the function
<?php $HeaderName = get_field('header_name');?>
<?php echo $HeaderName;?>
However, when I try to get the correct header to display using an if statement then both headers display. Any ideas why this would happen?
<?php $HeaderName = get_field('header_name');?>
<?php
if ( $HeaderName = 'SpeechTherapyHeader' ) :
get_header( 'SpeechTherapyHeader' );
else :
get_header();
endif;
?>
This is the solution: I had to remove the single quotes around ‘SpeechTherapyHeader’
<?php $HeaderName = get_field('header_name');?>
<?php
if ( $HeaderName = SpeechTherapyHeader ) :
get_header( 'SpeechTherapyHeader' );
else :
get_header();
endif;
?>
Maybe it wasn’t working as well as I thought. I tried adding a 3rd header, but it just keeps outputting
SpeechTherapyHeader
<?php $HeaderName = get_field('header_name');?>
<?php
if ( $HeaderName = SpeechTherapyHeader ) :
get_header( 'SpeechTherapyHeader' );
elseif ($HeaderName = Secondary ):
get_header(‘Secondary’);
else :
get_header();
endif;
?>
Okay the issue here is I was using the single equals sign “=” and setting the value each time. I needed to use “===”
system
Closed
5
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.