I have the following php code inside the part of my website.
It’s a very simple code which adds the meta name robots, wmt tool verification meta and the rss meta.
It works OK but for one thing:
When I look in the source of my page with IE or Fireforx, I don’t see new lines between the meta’s. They are displayed one after another on a single line.
How do I add new lines? any ideas? Would there be any issue if I let them like this?
Here is the code:
if((is_home() && $currentpage == 1) || (is_single() && $title != 'Online' && $title != 'Cam') || (is_category() && $robots == 'y')){
echo '<meta name="robots" content="index,follow"/>';
} else {
echo '<meta name="robots" content="noindex,follow"/>';
}
if(get_option('enable_wmt') == 'y'){
echo '<meta name="google-site-verification" content="'.get_option('wmt').'"/>';
}
if (is_home() && $currentpage == 1){
echo '<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="'.$site_current.'/feed/"/>';
}
Well, actually the cause is simply that you do not specify any linebreaks. You have to output linebreaks as well if you want them to be generated, just like with every other conent.
I usually use this syntax, since it does not make the code unreadable:
Explanation: the sequence
\nis the description of a single linebreak character. The character cannot be entered directly outof two reasons:it is a whitespace, so very hard to handle for editors and
the ‘normal’ linebreak has special meaning in language syntax.
When using that linebreak character inside php you must enclose it in double quotes (
"). Only when contained in double quotes such special characters are interpreted by php. If you use single quotes (') those sequences remain uninterpreted. That is a difference that comes in handy now and then… In this case it helps us to stick with the simple and easy to read way of how you hand over the strings to be output to the echo command. We use the colon (.) to concatenate two strings and use double quotes to have the special character sequence interpreted.Another note for the sake of completeness: there are different way of how linebreaks are specified under different circumstances. Most notably this is handled different und different operating systems. The classical unix systems (thus also Linux) use the character cited above (
\n, how 0x10 in hex notation), MS-Windows uses two characters to specify a single linebreak:\n\r(hex 0x10 0x13, or linebreak and carriage return). Older MacOS systems used something different again, though the current MacOSX systems are also unix based. Since the internet is traditionally unix land (has been developed and enhanced under unix like systems) the unix like behaviour is found and expected in many parts of internet technologies.