Previously, you had to create a theme options page to provide theme users with a way to customize the site or theme side. However, the best approach now (the expected approach for topics submitted to the topic directory) is to use a custom program. This is the second post in the word press development series for intermediate users. This series is the follow-up part of the WordPress development tutorial. It introduces the basic knowledge of developing websites with WordPress, the method to start coding with PHP, and the construction method of topics and plug-ins. This guide will show you how to add custom features to a topic. We will deal with:
Overview of customizators and preferences, hooks and functions required to interact with customizators, adding parts to customizators, using parts to add control settings (including colors, text, and radio buttons), and implementing user input in themes. We will also discuss how to allow users to add text to the site, and how to use color selectors in custom tools to modify styles. Note: PHP is the default language for WordPress, and code snippets will be referenced in this series, so you must have a practical knowledge of PHP. Let’s go. Have you missed the word press development series for intermediate users? Here, you can view all 7 posts. The
WordPress development for intermediate users: detailed topic development for intermediate users WordPress development for intermediate users: WordPress development for intermediate users: WordPress development for plug-in building intermediate users: WordPress development for user-defined post types and classification intermediate users: query and cycle intermediate companies User oriented WordPress development: WordPress development for intermediate users of custom fields and metadata: internationalization. To emulate wpmu dev members’ extensive knowledge of word press, pearleview, instructor feedback, and this part of the series of articles required for certified free learning, you need a work topic. You can use your own theme (which means you have to modify my code to work with the theme), or you can use the theme you worked on in part 1 of this series. If necessary, you can the final topic from Part 1 of the course source file. The
In addition, you need to use a development site (possibly on your local computer) and a code editor. How many skills do you need? Here are the ways to set up your local environment on windows and on MAC: You can also view the 24 best text editor guides for WordPress developers. What is a custom machine? If you have developed WordPress knowledge to learn this course, you should have used customizer before, so you don’t need much introduction. Using the customizer, the site administrator can not only change the content or design of the site, but also add parts, menus, etc., and preview what happens in the work in real time. The
Currently, the custom tools for my demo site include: There are now four basic parts. Site ID – location for editing site title and description. Menus – places where menus can be added and edited. Component – adds a component to the registered component area. Static front page – used to set a static page as the home page. These are added by word press, not themes. The theme has not added a custom part or control. This part of the series adds two parts. One for title content and one for color. The
The class, hook, and method customizers used by the client are used to add the customizer functionality to the topic.
It has its own API, including various classes, hooks, and functions that require interaction. Let’s look at the following points: The customize\u register\u registration task hook is a hook used to access custom programs. Most custom functions must be connected here. You can also use the wp_head hook to add custom styles to the male part of the website according to the settings of the custom program. In this part of the lesson, use colors. The wp\u customize\u manager class defines how wp\u customize\u manager settings, controls, and sections work. Use the methods of this class when interacting with custom programs. Some classes apply to specific types of controls that define the default way of working. This includes wp\u customize\u color\u control and wp\u customize\u control classes. You can create your own class to expand it and define a custom version of the control to be used in the theme. To create a section, use the $wp\u customize->add\u section() method. We will show you the relevant parameters in a further process. To add a control, use the $wp\u customize->add\u control() method. To add settings that allow the control to execute internally, use the $wp\u customized->add\u setting() method. The last three methods I introduced are not independent functions, but class methods, so they are not functions, but methods. The
In this part of the lesson, when you set up custom sections, controls, and settings, you do the following: Start: create a custom program’s include file before we start adding code to the custom program, let’s add a file that contains all the code. This is the function of the theme. Let’s create an include file instead of adding it to the PHP file. In the theme folder, create a folder named. Its internal customizer. Create an empty file named PHP. Functions Open the PHP file. Add the following at the top: Save and close the load summary 1392d651b0f99338446eb330050f2 function file. Second, the new customizer. We will start with the PHP file. The
New customizer. The male add\u setting() method that opens and opens a PHP file has two parameters. The set unique ID default value $wp\u customize->add\u control() method contains the new wpmu\u customize\textarea\u control parameter. This parameter informs WordPress that a new instance of the created class is being created. The new class has three parameters:$ Wp_customize, objects in this class. Unique ID of the setting. Value arrangement: labels ready for translation (see later in this lesson for details). The section that contains this control. The setting for sending data, that is, the unique ID of the created setting. Now, if you go back to your site’s customization program and refresh the screen, the contact details section is displayed. When you click the corresponding section, the following controls will be displayed: At present, if you enter anything in this control, it will not be displayed on the website, but will be modified later. Let’s add some controls in the second part. After adding color controls and settings, let’s add several color controls that site administrators can use to modify the color configuration of the theme. Because four controls are added here, we will set the $textcolors variable, then use this variable to process each color to be added and generate controls for each color. Let’s set this variable first
Add the following under the code you just added to the text control: Save the load summary 1392 d651b0f99338446eb330050f2 file. This generates the $textcolors variable, which contains an array of wpmu_color1, wpmu_links_color2, wpmu_links_color2 values. For each, there is another secondary array with slashes, default colors, and labels. Please look back. New PHP technology has just been used. Nested arrangement inside variables! Now let’s create the control. Instead of creating a new color for each color, use foreach () to repeat the four colors already defined in the variable. Add the following under the code you just added to set the variables: Save the load summary 1392 d651b0f99338446eb330050f2 file. This will repeat each color and add the following: There are two parameter settings: an array of values, which contains the default values and option control types re imported in the variable array using the unique ID of the slug of the variable array. Control uses three parameters and a new wp\u customize\u color\u control: label, part, and setting in the unique identity array using $wp\u customize slug. This is very similar to what you do with a text control, but using the $textcolors variable uses the value of a defined array. If desired, you can go back and apply the same technique to the text controls and settings that you have added. Now let’s take a look at the site’s customizer. Displays the color configuration table section that contains the four color controls. As with the male text control, if you use the color selector to select a new color, the website has not changed. Then I’ll make a change. In a topic, adding controls and settings to custom controls and settings to implement a custom program is a good first step, but you must make it work. That is, WordPress must import the settings stored in the database and add the code output to the topic to the topic Two actions are required: For contact details, add a hook to a header that can output text. For color, create a style connected to the wp\u head hook to modify the color value of the specified class in the theme. First, contact information. Add the text to the topic. We are the custom characters inside the function to be connected to the action hook. Create a function that outputs text in a PHP file. That is, you must create another action hook on the topic inside the title. Title of the topic. Open the PHP file. Find the maleline and add it directly below. Load the summary 1392 d651b0f99338446eb330050f2 header. Save and close the PHP file. Now, there is a hook to connect functions. Let’s create that function. Customizer Add an empty function in PHP: add the following contents inside the load summary 1392 d651b0f99338446eb330050f2 function: Save the load summary 1392 d651b0f99338446eb330050f2 file. This adds four types of annotations: paragraphs that contain addresses of address elements phone numbers corresponding to addresses links that contain e-mail addresses. To do this, we use the get\u theme \u mod() function, which gets the storage data of the relevant settings. There are two parameters: the set ID and the default value. Now, when you view the site, the title displays the default text. The text inside the element where the header right class is located has the right alignment defined by the theme’s style sheet, so the text has been correctly aligned. Title part area
You can adjust the margins below to add space under the corresponding search box (or adjust the margins under the included header element). Now, edit the text in the customization program. After adding styles to the theme, let’s create functions for the color configuration table. Before adding code, let’s determine the target of each color. The first color (wpmu_color1) applies to titles, links in navigation menus, and footnote backgrounds. The second color applies to the navigation background. The third color applies to links in link or accessed state. The fourth color applies to hover or active links. You can apply color configurations to other elements, or add more colors to other elements or classes. You must create a function before adding a style. Customizer Add the following function to PHP: save the load summary 1392 d651b0f99338446eb330050f2 file. It is connected to wp_head action hook, so the content of the function will be added to the male part of each page. Adding CSS to each page is not as good a habit as using style sheets, so it is not ideal. But this is the only way to do it, because each color is added by a function, and PHP functions cannot be encoded with style sheets. Inside the male element opened at the end of the function, there are four variables that can be used to define the color. I want to add. Under variables, but still inside functions, add the following: The load summary 1392 d651b0f99338446eb33005050f2 has a closed PHP tag, followed by the male element about our style. Next, add a style for the first color. Load summary 1392 d651b0f99338446eb330050 now save the second color: load summary 1392 d651b0f99338446eb330050 the last two link colors: load summary 1392 d651b0f99338446eb330050 file. Depending on the topic, you can adjust the target elements and classes slightly. You can now navigate to the site administrator’s customization program to adjust the color configuration. Here is a very gorgeous plan! This may not be the color configuration table selected by the website, but it shows the implementation method of color in the theme. We will try more fashionable ones, then save and publish them. Users can now use the custom program to modify the color configuration table of the website. Topic: add your own settings and controls now you have added some text controls and color configuration tables, so please add more settings and controls in the theme and apply the skills you have learned. Possibilities include: Upload media – to do this, create a new instance of the wp\u customize\u image\u control class in a similar way to what you have done in the color control class. Then, you must use a hook to add the image to the site in a manner similar to what you have already done with the contact details (is there a logo in the title?) Specify image style – after adding a media upload, you can create several options to specify the style of the image, such as displaying the logo to the left of the site title or changing the site title using the logo. For controls, you can use radio buttons by defining \
This is because you are using the option to add classes to the template file instead of adding styles to the appropriate classes in the tile drawing. Page layout – add page layout options such as full width, include or exclude columns, or sidebars. You can do this for a specific content type (for example, a single post or page) using the conditional tag of the wp\u head add-on function with related styles added. In other words, use the radio button and use the get\u theme \u mod() function to set the style. Position of element – you can move the sidebar left or right, or you can add an option to move the title image above or below the menu or site title. Again, you need to use get_theme \u mod() to define the style radio buttons and variables. More text options – create sidebar or footer text that you can edit in a custom tool. Sidebar of the topic. PHP and footer. Connected to the hook that was added to the PHP file. Behavior guide buttons – use text controls to create editable behavior guide buttons, and use radio buttons to define whether they are activated and where they are displayed. Then, use the conditional tag of the function that added the box (by hooking) to determine whether the box should be added to the appropriate location. These are just some of the possibilities you can use. Why not try them? If you need more inspiration for custom controls, check out the wonderful custom themes available in the themes catalog and make sure you can recreate the tasks that the theme performs. Do not overuse. I don’t want to overwhelm users! To view the code created in this part of the series, don’t forget to get a copy of the theme from GitHub’s series source file. If blocking occurs anywhere or the code does not work, check the code before publishing the problem here. The best way to learn is to practice! Customization is a powerful tool, and customizer is an excellent tool that can change the site without subject users writing code. If others create themes on their own site, they have more flexibility in controlling and controlling the appearance of the site. If you create a site for the client, the custom program can edit contact details, sidebar text, and so on without writing code (or requesting action from the user). I hope this part of this series can provide a basis for customizing how the program works and how to add settings and controls in it, and provide inspiration for you to add to your own theme. I wish you a pleasant experiment! That’s right. Does the extensive WordPress knowledge, pearreview, instructor feedback, and certified free learning available to wpmu dev members help start the tutorial? Why do you want to learn WordPress development? What else do you want to know? Please tell us the following comments. Tags: developing multiple sites