0

I'm learning PHP and how customization works on Wordpress. I'm doing a tutorial where they give you this code

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' );

And then this one

<?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');
?>

My question is, do I have to paste this two codes just in the way they are on functions.php or do I have to lock them into the <?php and ?> labels (the two entire codes)? Thank you.

2 Answers 2

1

They are PHP functions, so they need to be enclosed in <?PHP ?> tags. Whether you enclose both functions in one pair of tags, or use a separate pair of tags for each function is mostly a matter of preference. Just make sure you're not putting PHP tags inside other PHP tags

Sign up to request clarification or add additional context in comments.

1 Comment

To the OP: Keep in mind that this is going into functions.php...which usually includes opening <?php tags at the beginning. Nested <?php tags would be bad...
0

Just write <?php at start of functions.php file and then you can write any php code inside.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.