How to style injected code in header section?

Trying to add custom code to header section <head>..</head>of the blog by adding this code to child-theme functions.php

// Add scripts to wp_head()
function child_theme_head_script() {
 if ( is_singular( 'article' ) ) {
         $cjt = ''.'<meta name="date" content="' . get_the_date().'" />' . '';
         $ct = ''.'<meta name="title" content="' . get_the_title().'" />' . '';
} 
echo $cjt.$ct;
}
add_action( 'wp_head', 'child_theme_head_script' );

Actually, this code add this result to html header:

<meta name="date" content="July 29, 2015" /><meta name="title" content="Delays in the post-marketing withdrawal of drugs to which deaths have been attributed: a systematic investigation and analysis" />

as you can see, the generated meta tags are displayed in the header section but directly before </head>. Also, all meta tags are on the same line.
What i need exactly is:

  1. How can I make this code to display the meta tags at the top of the
    header section right after <head>?
  2. How can I put each meta tag on a separate line?

for the second question i need meta tags to be like this:

<meta name="date" content="July 29, 2015" />
<meta name="title" content="Delays in the post-marketing withdrawal of drugs to which deaths have been attributed: a systematic investigation and analysis" />

I tried to add <p>...</p> to the code but the result was:

<p><meta name="date" content="July 29, 2015" /></p><p><meta name="title" content="Delays in the post-marketing withdrawal of drugs to which deaths have been attributed: a systematic investigation and analysis" /></p>

So, any suggestions please?

Solutions Collecting From Web of "How to style injected code in header section?"

How can I make this code to display the meta tags at the top of the
header section right after ?

You probably can’t. Typically wp_head() is called at the end of the </head> section, but that is theme dependent. You don’t have any control.

How can I put each meta tag on a separate line?

Use double quotes and \n

$cjt = '<meta name="date" content="' . get_the_date().'" />'."\n";
$ct = '<meta name="title" content="' . get_the_title().'" />'."\n";

(No idea why you are concatenating empty strings to the beginning and end of your strings, by the way.)

Back to the point, why? You are trying to format code that the browser will render the same whether formatted or not. What you are doing is irrelevant. In fact, it is worse than irrelevant. It introduces unnecessary characters and increases your page size, slowing your site load time. Take a look at any Google search result page. Are you going to argue with Google?

The habit of formatting HTML source harkens back to the days when we were writing HTML source. Doing so made the code readable and maintainable. Now, I write PHP, and given that you are writing WordPress, so do you. Format your PHP source and nevermind the HTML. I actually make an effort to print the HTML all on one line, Google style, but if you don’t want to bother with that at least don’t waste your time trying to format it.

Additionally, per TheDeadMedic’s comment below, your echo should be inside the if conditional, not outside of it.

if ( is_singular( 'article' ) ) {
    $cjt = '<meta name="date" content="' . get_the_date().'" />';
    $ct =  '<meta name="title" content="' . get_the_title().'" />';
    echo $cjt.$ct;
}