Avatar of techvagabond
techvagabondFlag for Australia asked on

Wordpress PHP if Statement not working correctly

Below I have a piece of code in which I'm certain I'm doing something very stupid, as does come with working on a Saturday.
I have in my functions.php a declared true/false variable. If the drop down is set to yes, or true, then it does display the text "Test" and then input the code for the wordpress comment engine (The comment section does not appear)

The second part, if it is not equal to 'yes', then it returns a seperate DIV tag. This also works.

So the IF statement seems to be working, but it just does not seem to be working with the <?php comments_template(); ?> WordPress hook.

Any Ideas?

<?php if (get_option('console_engine') <> 'yes')
	echo "Test <?php comments_template(); ?>";
		echo "<div id='test-root'></div>";

Open in new window


Avatar of undefined
Last Comment

8/22/2022 - Mon
Dave Baldwin

If you look at the "View Source", you will see that this line:

echo "Test <?php comments_template(); ?>";

puts the "<?php comments_template(); ?>" in the HTML code where it does nothing.  It does not get executed by PHP.  What is it supposed to do?

you're right, in the code generated in just puts in

test<?php comments_template(); ?>

Firefox source browser gives the php statement a pink colour which I've never seen before. I think it's taunting me.

Basically, that php hook is what you call to be able to leave or view comments on a particular wordpress page of blog post.

I'm trying to make it so that in the functions.php, the user has an option to turn the comment engine off if required.
Dave Baldwin

The pink means "What is this?", means Firefox doesn't recognize it.  Putting it in the 'echo' won't do what you want because it never gets executed.  I don't know where you need to put it.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

That looks like it'll do the trick :D