How to Edit and Optimize WordPress Child Theme Template Files and Features (Detailed Tutorial)

Our tutorial in this installment is still about child themes. We talked earlier about how to create a child theme. Now, let's see how toEditing template files for child themes(math.) genusHow to add new features to a child themeand howSolving some WordPress child theme problemsThe

How to edit template files of child themes

Most WordPress themes have templates, which are theme files that control the design and layout of specific areas within the theme. For example, the footer section is usually controlled by the footer.php fileis handled, while the header is handled by the header.php fileProcessing.

Each WordPress theme also has a different layout. For example, Twenty Twenty-One theme has header, content loop, footer widget area and footer.

If you want to modify the template, then you must find the file in the parent theme folder and copy it to the child theme folder. After that, open the file and make the required changes.

The father theme of this case is Twenty Twenty-One, which can be transferred to the/wp-content/themes/twentytwentyoneFile Manager. Then, right-click on the template file (e.g., footer.php) and choose"Reproduction".

图片[1]-如何编辑和优化WordPress子主题模板文件及功能(详细教程)-光子波动网 | WordPress教程、Elementor教程与故障修复

After that, enter the subtopic'sfile pathThe

When finished, click "Reproduction of documents"Just do it.

图片[2]-如何编辑和优化WordPress子主题模板文件及功能(详细教程)-光子波动网 | WordPress教程、Elementor教程与故障修复

It will then be redirected to the file path.

coerceEdit the footer.php fileRight-click on the file and select"Editing".

图片[3]-如何编辑和优化WordPress子主题模板文件及功能(详细教程)-光子波动网 | WordPress教程、Elementor教程与故障修复

For example, we would remove from the footer area "Proudly powered by WordPress'" link and add a copyright notice there.

The operation is also simple to delete<div class= "powered-by">Everything between the tags:

<div class="powered-by">
                <?php
                printf(
                    /* translators: %s: WordPress. */
                    esc_html__( 'Proudly powered by %s.', 'twentytwentyone' ),
                    '<a href="' . esc_url( __( 'https://wordpress.org/', 'twentytwentyone' ) ) . '">WordPress</a>'
                );
                ?>
            </div><!-- .powered-by -->

Then paste the code found under those tags in the example below:

<div class="powered-by">
<p>© Copyright . All rights reserved.</p>
</div><!-- .powered-by -->

You should now see these in a text editor:

图片[4]-如何编辑和优化WordPress子主题模板文件及功能(详细教程)-光子波动网 | WordPress教程、Elementor教程与故障修复

Continue and save the file to make the changes take effect.

After that, refresh and visit the front end of the site to see the newcopyright statementThe

图片[5]-如何编辑和优化WordPress子主题模板文件及功能(详细教程)-光子波动网 | WordPress教程、Elementor教程与故障修复

How to add new features to child themes

Functions.php file in the themeUse PHP code to add functionality or change the default functionality on your WordPress site. It works like a plugin for WordPress websites and is automatically activated with the current theme.

Many of our previous WordPress tutorials required the code snippet to beCopy and paste into functions.php. However, if changes are added to the parent theme, the files are overwritten when the theme is updated.

This is why we recommend using a child theme when adding custom code snippets. In this tutorial, we will add a new widget area to the theme.

We can do this by adding this code snippet to the functions.php file of the child theme. To be on the safe side, we always recommend using theWPCodeplugin, especially for newbies, so that you don't have to edit the functions.php file directly, which reduces a lot of risk.

Here is the code needed to add the functions.php file:

// Register Sidebars
function custom_sidebars() {

$args = array(


'description' =&gt; __( 'A custom widget area', 'text_domain' ),
'before_title' =&gt; '<h3 class="widget-title">',
'after_title' =&gt; '</h3>',
'before_widget' =&gt; '<aside id="%1$s" class="widget %2$s">',
'after_widget' =&gt; '</aside>',
);
register_sidebar( $args ).

}
add_action( 'widgets_init', 'custom_sidebars' );

After saving the file, you can access the WordPress dashboard'sAppearance" widget page.

It's a great place to see people who canAdd Widgets new custom widget area.

图片[6]-如何编辑和优化WordPress子主题模板文件及功能(详细教程)-光子波动网 | WordPress教程、Elementor教程与故障修复

Many other features can be added to the theme using custom code snippets.

How to fix WordPress child themes

Don't panic if you've never created a child theme before and encounter an error, it's normal. So, just to be on the safe side, we always do recommend thatBackup website data with backup pluginmaybeDeploying a new demo siteThe

If something goes wrong, you can always start over. For example, if you accidentally delete something that is required for the parent theme, then simply delete the file from the child theme and start over.

And the WordPress community andOur siteThere are plenty of resources, and no matter what problem you're having, there's a solution. If you can't solve it, you can also findProfessional TeamHelp you get it done!


Contact Us
Can't read the tutorial? Contact us for a free answer! Free help for personal, small business sites!
客服微信
Customer Service
Tel: 020-2206-9892
QQ咨询:1025174874
(iii) E-mail: [email protected]
Working hours: Monday to Friday, 9:30-18:30, holidays off
© Reprint statement
This article was written by Harry
THE END
If you like it, support it.
kudos0 share (joys, benefits, privileges etc) with others
commentaries sofa-buying

Please log in to post a comment

    No comments