Hook into wp_head(); in a plugin

I am following a tutorial that requires I put this code above wp_head();

<?php
    $example_position = get_theme_mod( 'logo_placement' );
    if( $example_position != '' ) {
        switch ( $example_position ) {
            case 'left':
                // Do nothing. The theme already aligns the logo to the left
                break;
            case 'right':
                echo '<style type="text/css">';
                echo '#main-header #logo{ float: right; }';
                echo '</style>';
                break;
            case 'center':
                echo '<style type="text/css">';
                echo '#main-header{ text-align: center; }';
                echo '#main-header #logo { text-align: center; float: none; margin: 0 auto; display:block; }';
                echo '</style>';
                break;
        }
    }
?>

I was hoping I could hook into it somehow from a plugin. After checking the codex I was hoping I could do something like this but it doesn’t work.

add_action('wp_head','hook_header');

function hook_header()
{

$output="<?php
    $example_position = get_theme_mod( 'logo_placement' );
    if( $example_position != '' ) {
        switch ( $example_position ) {
            case 'left':
                // Do nothing. The theme already aligns the logo to the left
                break;
            case 'right':
                echo '<style type="text/css">';
                echo '#main-header #logo{ float: right; }';
                echo '</style>';
                break;
            case 'center':
                echo '<style type="text/css">';
                echo '#main-header{ text-align: center; }';
                echo '#main-header #logo { text-align: center; float: none; margin: 0 auto; display:block; }';
                echo '</style>';
                break;
        }
    }
?>";

echo $output;

}'

Solutions Collecting From Web of "Hook into wp_head(); in a plugin"

Did you try this?

function hook_header() {
  $example_position = get_theme_mod( 'logo_placement' );
    if( $example_position != '' ) {
        switch ( $example_position ) {
            case 'left':
                // Do nothing. The theme already aligns the logo to the left
                break;
            case 'right':
                echo '<style type="text/css">';
                echo '#main-header #logo{ float: right; }';
                echo '</style>';
                break;
            case 'center':
                echo '<style type="text/css">';
                echo '#main-header{ text-align: center; }';
                echo '#main-header #logo { text-align: center; float: none; margin: 0 auto; display:block; }';
                echo '</style>';
                break;
        }
    }
}
add_action('wp_head','hook_header');