I want to create my own Widget which I want to appear under the rest of the original widgets of the original theme in the admin menu.
I want to do it in the cleanest and least sloppy way possible so my intention is not to touch the original theme files.
Instead of modifying the parent theme file, I have created one in the child theme by changing the name because the original is added using require_once
.
If the original file is called Widgets-area.php
, my name has been widgets-area-2.php
.
I had to call them different because otherwise there would be a conflict since being a require_once
can only be added once a same php file and I have only put the necessary code without repeating the code original.
The problem with doing this is that in the widgets menu in the admin menu, the widget that I created at the beginning of the rest appears instead of appearing below the other widgets as was my intention, since in the file where is the HTML code where these widgets are embedded if I have added it below the rest that is where I am interested. The require_once
is done in the functions.php
.
So I thought if there would be a clean way to glue with a enqueue_script
a archivo.php
like doing a require_once
but adding it after the file Original widgets are added, then adding mine.
I have tried the following in the file functions.php
:
function add_own_widget() {
/*--------------------------------------*/
/* Admin Panel
/*--------------------------------------*/
wp_enqueue_script( get_stylesheet_directory() .'/functions/return-smof-data.php' );
/*--------------------------------------*/
/* Include functions
/*--------------------------------------*/
require_once( get_stylesheet_directory().'/functions/widgets/widget-areas- 2.php' );
}
add_action('wp_enqueue_scripts', 'add_own_widget');
This from what I have been able to verify does not work.
Is there any way to get my widget to appear below the others?
I do not know what more details to provide. I have done this by adding the minimum code necessary for it to work, in the first way I mentioned but it appears at the beginning. The second way does not work.