Public Ticket #1643308
Modify so-widgets in child theme


  •  4
    MissZougou started the conversation


    I had to customize the Orion Recent Posts Carousel widget.
    I added a custom field (created with ACF plugin) to display by default for a specific category.

    I did the customization in :

    All works fine, as expected.

    My problem is that i'd like to make this customization in the child theme folder, as i don't want to loose all this with recycle theme updates.

    - I copied the folder of the widget in my child-theme.
    - I updated the tpl/orion_recent_posts_carousel-template.php with my code

    - and put this in my functions.php file (child-theme) :

    But this doesn't work.
    How can i override the widget in child-theme ?

    Thanks in advance for your help !

  •  347
    OrionThemes replied


    As widgets are not theme templates, the classic WordPress procedure for overwriting theme templates will not work. In order to keep your changes upon theme upgrade, the safest way is to duplicate and rename the widget you want to modify. As each widget is a separate php class, they must be renamed, as the name of any php class must always be unique. 

    Also in order to keep the new widget in your child theme, a widget folder in your child theme must be registered with the SiteOrigin Page builder. Let's start with this part:

    1. Register the widget folder in your child theme:

    Add this to your child theme functions.php file:

    function orion_child_add_widget_folders( $folders ){
        $folders[] = get_stylesheet_directory() . '/yourwidgetfolder/';
        return $folders;
    add_filter('siteorigin_widgets_widget_folders', 'orion_child_add_widget_folders');

    Change 'yourwidgetfolder' to your actual folder's name.

    2. Rename The widget:
    Copy entire widgets/so-widgets/orion-recent-posts-carousel/ to your child theme's widget folder. 

    2.1 Now rename this folder to wz-recent-posts-carousel

    2.2 Inside this folder, there is a file orion-recent-posts-carousel.php -> rename it to wz-recent-posts-carousel.php

    2.3 There is also a tpl folder inside theRecent post widget folder, inside there is a file orion_recent_posts_carousel-template.php -> Rename it to wz_recent_posts_carousel-template.php

    2.4 Open the /yourwidgetfolder/wz-recent-posts-carousel/wz-recent-posts-carousel.php file with a text editor. Now find and replace 'orion_recent_posts_carousel' with 'wz_recent_posts_carousel'.
    Also change the name of the widget, replace '(OrionThemes) Recent Posts' with '(Webozenith) Recent Posts'.

    3. Activate it:
    Now everything is ready, you just need to activate the new Widget. In WordPress Dashboard go to Plugins -> SiteOrigin Widgets. Find your (Webozenith) Recent Posts widget and activate it.

    This was the technical part, now you just need to replace the widgets in your content. 

    Let me know, how it goes.