Conectarse a wp_head(); en un plugin

9 nov 2014, 19:19:27
Vistas: 20.9K
Votos: 5

Estoy siguiendo un tutorial que requiere que coloque este código arriba de wp_head();

<?php
    $example_position = get_theme_mod( 'logo_placement' );
    if( $example_position != '' ) {
        switch ( $example_position ) {
            case 'left':
                // No hacer nada. El tema ya alinea el logo a la izquierda
                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;
        }
    }
?>

Esperaba poder conectarme a él de alguna manera desde un plugin. Después de revisar el codex, esperaba poder hacer algo como esto pero no funciona.

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':
                // No hacer nada. El tema ya alinea el logo a la izquierda
                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;

}'
0
Todas las respuestas a la pregunta 1
0

¿Probaste esto?

function hook_header() {
  $example_position = get_theme_mod( 'logo_placement' );
    if( $example_position != '' ) {
        switch ( $example_position ) {
            case 'left':
                // No hacer nada. El tema ya alinea el logo a la izquierda
                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');
9 nov 2014 19:31:57