Child Theme widget modification

Hello there,

I am trying to change the h-tags of a spezific widget of moesei pro. I have already read about the modification on google and on this side.

This is the code I’ve been trying to implement:

    function moesia_child_widgets() {
    	if (function_exists('siteorigin_panels_activate') ) {
    		unregister_widget( 'Moesia_Latest_News' );
    		register_widget( 'Moesia_Latest_Newss' );
    	}
    }
add_action( 'widgets_init', 'moesia_child_widgets', 99 );
require get_stylesheet_directory() . "/widgets/fp-latest-news2.php";

I have renamed the fp-latest-news in the child theme folder to fp-latest-news2.
Everytime I try to update my functions.php in the child theme there is an error:

‘Cannot declare class Moesia_Latest_News, because the name is already in use’

I hope anyone can help me.
All in all I am trying to change the

tags of this widget to

tags, if you have an easier solution for my problem.

Thanks so far!

Hello there,

Try renaming this line in your child theme’s /widgets/fp-latest-news2.php:

Moesia_Latest_News

with:

Moesia_Latest_Newss

which matches the registered widget class in this line register_widget( 'Moesia_Latest_Newss' );.

Regards,
Kharis
aThemes Support

Thanks for the answer so far!

I modified the code:

    function moesia_child_widgets() {
    	if ( function_exists('siteorigin_panels_activate') ) {
    		unregister_widget( 'Moesia_Latest_News' );
    		register_widget( 'Moesia_Latest_Newsnew' );
    	}
    }
    add_action( 'widgets_init', 'moesia_child_widgets', 99 );
    require get_stylesheet_directory() . "/widgets/fp-latest-newsnew.php";

and changed the class name.
I don’t get an error anymore. The original widget “moesia_latest_news” is unregistered. But the new one doesn’t show up.
Any suggestions?

Hello there,

Renaming only the file name won’t change anything, I am afraid.

What you need to do is match the class name as specific in this line:

   register_widget( 'Moesia_Latest_Newsnew' );

with the name of the class in your /widgets/fp-latest-newsnew.php file. It would read something like:

   class Moesia_Latest_Newsnew extends WP_Widget {

Regards,
Kharis
aThemes Support

Sorry, my bad!
I already renamed the class in /widgets/fp-latest-newsnew.php. I forgot to mention it. But it still doesnt work

Try replacing your active widget with the new one you just created. If it is in the widgets area (go to Appearance > Widgets), remove the existing one and use the new one.

Regards,
Kharis
aThemes Support