Created
July 18, 2017 23:26
-
-
Save worduoso/9439aee7c5b91380527a06ac17498d41 to your computer and use it in GitHub Desktop.
Add custom options to WordPress website to use (display) in your theme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* add custom section to theme customizer (Appearance -> Customize) | |
*/ | |
function worduoso_customize_register($wp_customize) { | |
// add section to customizer | |
$wp_customize->add_section( 'worduoso' , array( | |
'title' => __('My Custom Section','worduoso'), | |
'priority' => 10, | |
)); | |
// we will add 2 fields - URL and text. Of course, you can change this part to add as many as you need | |
// add login link URL to customizer | |
$wp_customize->add_setting('worduoso_login_link', array( | |
'default' => '', | |
'capability' => 'edit_theme_options', | |
'type' => 'option', | |
)); | |
$wp_customize->add_control('worduoso_login_link', array( | |
'label' => __('Login Link URL', 'worduoso'), | |
'section' => 'worduoso', | |
'settings' => 'worduoso_login_link', | |
)); | |
// add login button text to customizer | |
$wp_customize->add_setting('worduoso_login_text', array( | |
'default' => '', | |
'capability' => 'edit_theme_options', | |
'type' => 'option', | |
)); | |
$wp_customize->add_control('worduoso_login_text', array( | |
'label' => __('Login Link Text', 'worduoso'), | |
'section' => 'worduoso', | |
'settings' => 'worduoso_login_text', | |
)); | |
} | |
add_action('customize_register', 'worduoso_customize_register'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$login_link = get_option("worduoso_login_link"); | |
$login_text = get_option("worduoso_login_text"); | |
?> | |
<?php if($login_link && $login_text): ?> | |
<div class="added-header"><a href="<?php echo $login_link; ?>"><?php echo $login_text; ?></a></div> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment