0

I have 5 WordPress sites and each site should have the same sidebar content. It is dynamically posted from userend and it should be common to all my WordPress sites. Without using iframe, how can I repost the same content that is in the right sidebar?

2

The short answer is you can't.

The long answer is that there are plenty of options to do so, but they're all extremely convoluted, bug-prone, and most assuredly not anything you want to be looking into if you're not a sophisticated PHP hacker who can gore through the WP code base blind-folded.

If you are, one option is to dodge the WP widget API through the use of a sidebar.php file in your themes instead of dynamic_sidebar() calls.

If you mean to make it work on themes you don't control, note the get_sidebar() function to that effect. It has two calls of potential interest:

    do_action( 'get_sidebar', $name )
    locate_template($templates, true)

But even then, not all themes call it, which brings us to dynamic_sidebar() and widgets.

Those are even trickier to hack in my experience. There are places like 'sidebars_widgets' or 'register_sidebar' or 'widgets_init' that you can try to hook into to "import" something in there that masquerades as a genuine widget area without actually being one.

Note, however, that even then your sidebar params would remain site-specific when dynamic_sidebar() gets called. The latter includes things like the following to potentially override things:

apply_filters( 'dynamic_sidebar_params', $params )
do_action( 'dynamic_sidebar', $wp_registered_widgets[$id] )

And there are heaps of other hooks and private APIs, tied to the sidebars themselves or widget configuration, that you need to monitor. No amount of asking WPSE will spare you the need to have a cold hard look at the WP code base.

I'd like to stress that last bit: you must read and understand the WP Widgets-related spaghetti code to make the slightest sense of the above. Moreover, it's extremely important to monitor any change to it in the foreseeable future if you proceed.

Failing to do either is a recipe for having your site blow up in your face or worse, because hacking into WP private APIs is prone to introducing buggy side effects, and subjected to frequent API changes. (The next of which, incidentally, is hot on the WP todo list.)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.