API Wordpress Customization


API Wordpress Customization

我正在学习PHP以及自定义如何在Wordpress上工作。我正在做一个教程,他们给你这个代码

function test_customize_register( $wp_customize )
{
    $wp_customize->add_setting( 'test_font_color' , array(
        'default'     => '#0000FF',
        'transport'   => 'refresh',
    ));
    $wp_customize->add_section( 'test_customize_section' , array(
        'title'      => __('Opciones Extra','my_test'),
        'priority'   => 30,
    ));
    $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'test_color', array(
        'label'      => __( 'Color de Testeo', 'mytheme' ),
        'section'    => 'test_customize_section',
        'settings'   => 'test_font_color'
    )));
}
add_action( 'customize_register', 'test_customize_register' );

然后这个

<?php
function test_customize_css() {
    if ( get_theme_mod( 'test_font_color' ) ) {
        ?>
            <style type="text/css">
                body {
                    color: <?php echo get_theme_mod('test_font_color'); ?>
                }
            </style>
        <?php
    }
}
add_action( 'wp_head', 'test_customize_css');
?>

我的问题是,我是否必须以它们在functions.php上的方式粘贴这两个代码,或者我是否必须将它们锁定到<?php?>标签(两个完整的代码)中?谢谢。

它们是 PHP 函数,因此需要将它们包含在<?PHP ?>标签中。是将两个函数括在一对标签中,还是为每个函数使用单独的一对标签,这主要是偏好问题。只要确保你没有把PHP标签放在其他PHP标签中。

只需在文件的开头写<?php functions.php然后就可以在里面编写任何php代码。