I have a wordpress site. In the footer.php I put this code:
global $wpdb;
$user_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users" );
echo "<p>There are currently {$user_count} members!</p>";
which works as intended (to display number of registered members).
Now I wanted to prepare it for CSS styling, so I tried to add an ID to the <p>
tag so that I could target it in the CSS afterward. I also placed a span around the number itself because I wanted it to be a different color. My code:
global $wpdb;
$user_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users" );
echo "<p id="memberCount">There are currently <span id="memberCountNumber">{$user_count}</span> members!</p>";`
However, doing this just caused the message to disappear from the footer entirely. What am I doing wrong and how may it be fixed?
Thank you.
The problem is not the ID, the problem is that those are unescaped double quotes in a string. They need to be replaced with escaped quotes
"
or single quotes'
.PHP is trying to interpret
memberCount
andmemberCountNumber
itself, instead of considering them as a part of the string.