我正在遵循一个教程,该教程要求我将此代码放在上面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;
}
}
?>
我希望我能从插件中以某种方式连接到它。在检查了抄本后,我希望我可以做这样的事情,但它不起作用。
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;
}\'
最合适的回答,由SO网友:shanebp 整理而成
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\');