Ideas

do_action("before_sidebar") / do_action("after_sidebar")

  1. karimzai
    Member

    12345

    We need to fire some actions before a sidebar is displayed or after a sidebar is displayed.

    It is important for:
    1. Filtering HTML generated by all the widgets in a sidebar.
    2. Outputting custom HTML in the beginning and the end of a sidebar.
    3. Detecting if a specific piece of HTML was generated by a sidebar or not.

    The function dynamic_sidebar() In the file wp-includes/widgets.php should have these lines:
    In the beginning of the function do_action('before_sidebar');
    and in the end of the function do_action('after_sidebar');

    It would really help developers add functionalities to the sidebars.

    Thanks

    Posted: 3 years ago #
  2. Rami Yushuvaev
    Member

    12345

    nice idea.

    Posted: 3 years ago #
  3. Michael Fields
    Theme Wrangler

    @karimzai
    if you look on line 84 of /wp-includes/general-template.php you will see the following code:

    do_action( 'get_sidebar', $name );

    Which will allow you to execute an action at the start of any sidebar included via the get_sidebar() function.

    Posted: 3 years ago #
  4. karimzai
    Member

    12345

    @mfields

    ya but with do_action( 'get_sidebar', $name ); you never know where the output of a sidebar ends.

    Posted: 3 years ago #
  5. Gtechsweeper
    Member

    I would like to program this into my theme. However, I'm not really sure how to do it.

    Posted: 2 years ago #
  6. Andy Macaulay-Brook
    Member

    12345

    At the end of your sidebar-whatever.php file put do_action('after_sidebar');

    Posted: 2 years ago #
  7. Ipstenu (Mika Epstein)
    Half-Elf Support Rogue & Mod

  8. Ipstenu (Mika Epstein)
    Half-Elf Support Rogue & Mod

  9. webaware
    Member

    12345

    @Ipstenu, this is not a dupe of the idea you linked, it is quite distinct. Before/after action hooks would allow plugin and theme developers to modify the output of widgets, rather than just wrapping them in some pretty. See here for an example, where I was lucky enough to have access to the code calling dynamic_sidebar():

    http://snippets.webaware.com.au/snippets/filtering-the-output-of-wordpress-widgets/

    The action "dynamic_sidebar" is nice, but only tells you when the sidebar starts; you need to know when the sidebar ends too, so that you can capture a sidebar's output using PHP output buffering and then modify it accordingly.

    Ideally, the action hooks would both pass a parameter identifying the sidebar, so that the hooker can apply output buffering and filtering to only the sidebars of interest.

    Incidentally, this has nothing (directly) to do with the "get_sidebar" action Michael Fields is referring to, because the issue is widget zones, not sidebar templates.

    Posted: 8 months ago #

RSS feed for this topic

Reply

You must log in to post.

  • Rating

    12345
    13 Votes
  • Status

    Duplicate of another idea