Skip to content
Advertisement

Programmatically inserting a widget into WordPress sidebar

I have been using this code on PHP 7.0, but decided to upgrade to 7.4 tonight. This code automatically inserts widgets into WordPress sidebar, but it no longer works.

JavaScript

From my research, it seems to be a problem with “[]” not initializing arrays anymore.

I’ve tried every single way I know how, but can’t get this to work. I’ve always initialized arrays with [], so I’m sort of lost.

This is an example of the input data:

JavaScript

Where $sidebar_name would be, for example, ‘right-sidebar’.

Advertisement

Answer

I was finally able to solve the problem by properly initializing the arrays… this is an edited version of the code made for my purposes, but here are the main changes:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement