Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMontalvo Miguelo
24,789 PointsWhy you are closing the php tag in your wp-head-callback ?
<?php
// Callback function for updating header styles
function wpt_style_header() {
$text_color = get_header_textcolor();
?> // <<<--- THIS
<style type="text/css">
#header .site-title a {
color: #<?php echo esc_attr( $text_color ); ?>;
}
<?php if(display_header_text() != true): ?>
.site-title {
display: none;
}
<?php endif; ?>
</style>
<?php // <<<--- THIS
}
?>
4 Answers
Chris Shaw
26,676 PointsHi Montalvo,
This is because we're using static HTML within the function, this is a common practice and is something you will see quite a lot during WordPress theme development.
Hope that helps.
Jamie Burton
11,144 Pointsif you close the php tags you can write pure html. You don't have to do this as you can just use php 'echo' to echo out elements. It is just far easier to read if you close the php and then write in pure html, you then open up the php tags again after completing the html
<?php
function hello() {
echo '<h1>hello world</h1><p>header with paragraph underneath</p>';
}
?>
is exactly the same as:
<?php function hello() { ?>
<h1>hello world</h1>
<p>header with paragraph underneath</p>
<?php } ?>
Montalvo Miguelo
24,789 PointsIs a kind of echoing the html or what does it mean?... It breaks if I remove those tags.
<?php
function foo() {
?> // closing
<style>/* css here*/</style>
<?php // opening
}
Glenn Basgaard
7,987 PointsFigured I'd give another explanation attempt at this just cause. The way I understand it is that you can't write html directly inside of php. Sure you can echo it like the above answers state, but in this example the <style> tag isn't being echoed in php.
Therefore that's why the php is closed above it and reopened for a brief conditional statement php tidbit and then closed again before the closing </style> tag. The reason the php is reopened beneath the </style> and above the } is because the function you're righting function wpt_style_header()
IS php.
If you didn't have php opened up again before the } closing of the function, then it'd fail because the whole of the function wouldn't have been in php. Hopefully this rambling made some sense and helps somebody :)