简体   繁体   中英

Wordpress child theme - modifying file of includes folder

I know there are many others who are trying to deal with that problem, but I didn't find an answer.

I'd like to modify a file which is located in the includes folder of a theme.

I need to change the following line:

$html .= '<span class="profile-widget-info-item"><i class="fa fa-star"></i> <a href="'.get_author_posts_url(get_current_user_id()).'">'.__('Channel','mars').'</a></span>';

of this file: http://pastebin.com/Qm5r9NeW

How can I do this in my child theme ?

Thank you all in advance, Jake

Copy the file you have pasted to your child theme.

At the very top you will see an if statement that is checking if a function already exists. By placing this file in your child theme, the file will run first and prevent the parent theme from adding the function. You will need to change the name of the widget class so you don't cause a conflict. I've changed the class name from Mars_LoginForm_Widget_Class to Jake_LoginForm_Widget_Class .

if( !defined('ABSPATH') ) exit;
if( !function_exists('Mars_LoginForm_Widget') ){
    function Mars_LoginForm_Widget() {
        register_widget('Jake_LoginForm_Widget_Class');
    }
    add_action('widgets_init', 'Mars_LoginForm_Widget');
}

Now you also need to update the class name in the class definition to match the name you've given the class above.

class Jake_LoginForm_Widget_Class extends WP_Widget{

After that just make sure you are including this file in your child theme and then you can freely edit the widget class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM