Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Hiz As the title says, i am looking for inserting a function's output before sidebar's first widget, and one in the end after teh last widget, is it possible?
thanks in advance.

share|improve this question

3 Answers 3

You can create your own actions using do_action, like this:

<?php do_action('before_sidebar'); // you can name it whatever you want ?>
<?php if ( is_active_sidebar('main-sidebar') ) : ?>
    <ul>
        <?php dynamic_sidebar('main-sidebar'); ?>
    </ul>
<?php endif; ?>
<?php do_action('after_sidebar'); ?>

and use add_action() normally:

add_action('before_sidebar', 'before_sidebar_function');
add_action('after_sidebar', 'after_sidebar_function');

UPDATE: depending on the codex you can use wp_meta hook:

Runs when the sidebar.php template file calls the wp_meta function, to allow the plugin to insert content into the sidebar.

but it should be added by theme authors.

This page might be helpful Full Action Hooks Reference.

share|improve this answer
    
k so that means there isn't an already made action for it. i am working on a plugin this might not work as the user wud have to add the sidebar name or add it before sidebar.. etc. –  Ayaz Malik Jun 12 '12 at 12:13
    
If there was sidebar actions they should be on the action reference page on the codex. –  Peter Jun 12 '12 at 14:03
    
i already went through it, can't find anything like what i need and stated above. i am actually making my 1st plugin.. so new to this. as i see a way around is i would need to register a widget with required function in ti ? and the user wud need to add it from widgets area right ? or is there a way around? –  Ayaz Malik Jun 12 '12 at 15:19
1  
yes widgets will do the job, it's not a big deal if the user will have to activate the widget. –  Peter Jun 13 '12 at 6:29

Yes. Put your function, and anything else you want, before and after the dynamic_sidebar function. For example.

<?php if(function_exists ('my_function')) {
    my_function();
} ?>

<p>This is above the first widget.</p>

<?php if ( ! dynamic_sidebar( 'sidebar-1' ) ) : ?>

<?php endif; // end sidebar widget area ?>

<?php if(function_exists ('my_second_function')) {
    my_second_function();
} ?>

<div>
<p><a href="http://www.agreatsite.com">Blog Link</a></p>
</div>

http://codex.wordpress.org/Function_Reference/dynamic_sidebar

Put the function inside a plugin, or even easier, inside your theme's functions.php file.

share|improve this answer

There are two options that may not yield the results you are looking for, but it's something.

Hooking a function onto the sidebar?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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