• Hi all, I’m trying to work out how to display certain widgets on certain pages. My plugin has a sidebar widget associated with it, but I don’t want it displayed on every page. What I’d like to do is search the_content for my plugin tag before widgets get initialised, but I don’t think this is possible due to WordPress’s load order. Is there a workaround?

Viewing 5 replies - 1 through 5 (of 5 total)
  • What specific criteria does your plugin need for deciding whether to display or not? There are several ways to do this, but your question is too vague.

    Thread Starter wuh

    (@wuh)

    Well, I know that I could do it for example by specifying the page_id where the tag is inserted, but I don’t want to hard code it like this.

    widgets_init should make a call that checks whether the page content contains the relevant tag (i.e. [call_my_plugin]). However, it is my understanding that the widgets_init action always occurs before the_content filter, so I can’t do that. Does that make more sense? Maybe I can remove the widget later?

    The actual widget code, the part that outputs the xhtml into the sidebar when called by the dynamic sidebar manager, is certainly free to look at any global variables and make decisions based on that, the time of day, the weather in New York, server load, user being logged in, a random number, you name it…

    Thread Starter wuh

    (@wuh)

    $post->post_content is what I needed, thanks for your pseudo-help

    Ask a clear question and you’ll get a clear answer… can’t read minds. Sorry I had to be so general.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Knowing which page_id a plugin is called from’ is closed to new replies.