ashh Danaa
ashh Danaa

Reputation: 3

API Wordpress Customization

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.

Upvotes: 0

Views: 58

Answers (2)

Dre
Dre

Reputation: 2953

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

Upvotes: 1

Mohsin Rafi
Mohsin Rafi

Reputation: 539

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

Upvotes: 0

Related Questions