Wednesday, January 20, 2021
  • About
  • Advertise
  • Careers
  • Contact
  • PHP
    • Codeigniter
    • WordPress
    • YII2
  • Python
    • Django
  • .Net
  • Digital Marketing
    • SEO
    • Social Media Marketing
    • Affiliate Marketing
    • Email Marketing
  • Academic Projects
  • Login
No Result
View All Result
Home PHP Wordpress

Create Custom Controls for WordPress Theme

Athira Rajeev by Athira Rajeev
June 2, 2020
in Uncategorized
3 min read
0
Create Custom Controls for WordPress Theme
0
SHARES
26
VIEWS
Share on FacebookShare on Twitter

Hi,

This tutorial covers how we can create a custom control for your word press theme.

Related posts

Top 10 Free Keyword Research Tools in 2020

May 18, 2020
How to Create a Simple WordPress Theme from Scratch – Part 4

How to Create a Simple WordPress Theme from Scratch – Part 4

January 22, 2020
www.codextreme.in www.codextreme.in www.codextreme.in
ADVERTISEMENT

Theme Customization API helps WordPress developers to customize and add controls to the “Appearance” → “Customize” admin screen. The Customizer shows the preview of those changes in real time.

It provides a unified interface for users to customize various aspects of their theme and their site, from colors and layouts to widgets, menus, and more.

If you are new to WordPress custom theme developing , please visit here to learn it from scratch. After that open theback born of your theme called functions.php. Create a new function for customize, then register this function using add_action() hook.

Adding New Section, Settings and Controls

Section: When you add a new custom control, must be added a section.

To add a new section to your Theme Customizer, you need to call the $wp_customize->add_section() method.

$wp_customize->add_section( 'mytheme_new_section_name' ,
 array(
    'title'      => __( 'Section Name', 'mytheme name' ),
    'priority'   => 30,
) );

Settings: Customizer settings are used to get/set some settings for your theme.

To add a new setting to your Theme Customizer, you need to call the $wp_customize->add_setting() method.

$wp_customize->add_setting( 'theme_custom_section_unique _name' , array(
    'default'   => 'default value for the control',
    'transport' => 'preview mode  value, value may be postMessage or refresh',
) );

Control: It is an HTML form element that renders on the Theme Customizer page and allows admins to change a setting, and preview those changes in real time. Controls are linked to a single setting, and a single section.

$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'theme_custom_section_unique _name', array(
	'label'      => __( 'label Name', 'mytheme name' ),
	'section'    => 'your_section_id',
	'settings'   => 'your_setting_id',
) ) );

After understanding sections,settings and controls, copy these into your custom function created in functions.php. Also don’t forget to replace the section,settings name with your custom name. Register the function by using the hook add_action( ‘customize_register’ , ‘function name’); .

Below shows an example for creating a top bar custom customizer.

// topbar customizer
function hardycodes_topbar_customize( $wp_customize )
{

$wp_customize->add_section('hardycodes_top_bar', array(
    'title'      =>; __( 'Top Bar', 'hardycodes' ),
    'priority'   => 30,
));

$wp_customize->add_setting('hardycodes_email', array(
    'default'        => 'info@example.com',
    'capability'     => 'edit_theme_options',
    'type'           => 'option',
));



$wp_customize->add_control(
    new WP_Customize_Color_Control($wp_customize,'hardycodes_email',
        array(
            'label'      => __('Email', 'hardycodes'),
            'section'    => 'hardycodes_top_bar',
            'settings'   => 'hardycodes_email',
            'priority'   => 10,
            'type'       => 'text'

        )) ); 
}
add_action( 'customize_register' , 'hardycodes_topbar_customize');

The result is like this,

Customizing Section
Top Bar Customizing.
Previous Post

Top 10 Free Keyword Research Tools in 2020

Athira Rajeev

Athira Rajeev

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

RECOMMENDED NEWS

Email Using PHP

3 years ago
PHP $GLOBALS

PHP $_SERVER

2 years ago

Jquery Ajax-load()

3 years ago
Dependent Dropdown Using Ajax Jquery in Codeigniter

Dependent Dropdown Using Ajax Jquery in Codeigniter

2 years ago

FOLLOW US

  • 112 Fans

BROWSE BY CATEGORIES

  • No categories
moleculetechnologies.com moleculetechnologies.com moleculetechnologies.com
ADVERTISEMENT

BROWSE BY TOPICS

404 Codeigniter Comment Commit CSV Custom Database Desktop Application error Export File management Framework Gmail List Content logo Mysql database PHP PHPDesktop PHPExcel PHP file management PHP file system PHPMailer Rate Reply Rolledback SMTP Star Transaction Upload wordpress
ADVERTISEMENT
ADVERTISEMENT

POPULAR NEWS

  • create PHP desktop application

    create PHP desktop application

    0 shares
    Share 0 Tweet 0
  • Export Data to Excel in PHP Codeigniter using PHPExcel Library

    0 shares
    Share 0 Tweet 0
  • Codeigniter Login with Captcha

    0 shares
    Share 0 Tweet 0
  • How to use PHPMailer with gmail smtp in codeigniter

    0 shares
    Share 0 Tweet 0
  • how to make a Nested comment-reply using codeigniter and MySQL Database

    0 shares
    Share 0 Tweet 0
HardyCodes

We bring you the best Premium WordPress Themes that perfect for news, magazine, personal blog, etc.

Follow us on social media:

Recent News

  • Create Custom Controls for WordPress Theme
  • Top 10 Free Keyword Research Tools in 2020
  • How to Create a Simple WordPress Theme from Scratch – Part 4

Category

  • No categories

Recent News

Create Custom Controls for WordPress Theme

Create Custom Controls for WordPress Theme

June 2, 2020

Top 10 Free Keyword Research Tools in 2020

May 18, 2020
  • About
  • Advertise
  • Careers
  • Contact

© 2020 HardyCodes - powered by CodExtreme Software Solutions.

No Result
View All Result
  • PHP
  • Codeigniter
  • WordPress
  • YII2
  • .Net

© 2020 HardyCodes - powered by CodExtreme Software Solutions.

Welcome Back!

Login to your account below

Forgotten Password?

Create New Account!

Fill the forms bellow to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In
This website uses cookies. By continuing to use this website you are giving consent to cookies being used. Visit our Privacy and Cookie Policy.