Community Forums › Forums › Archived Forums › Design Tips and Tricks › add_action within a function
Tagged: actions
- This topic has 6 replies, 2 voices, and was last updated 11 years, 1 month ago by
orbiterred.
-
AuthorPosts
-
January 12, 2014 at 9:31 pm #84898
orbiterred
MemberHey Everyone,
So after a few days I'm feeling like I'm starting to get the hang of things! I can see how Genesis is way easier to deal with than Thesis in the long run, that's for sure.
Anyways, my question is as follows.
Can I add an action within a function
Example:
add_action ( 'genesis_before_footer', 'sample_action' );
function sample_action() {
echo '<div class="mydiv">';
add_action( 'genesis_before_footer', 'another_action' );
echo '</div>';
}function another_action() {
echo '<p>Some Stuff here</p>';
}What I'm actually trying to do is add a few widgetized areas into that div (mydiv) but before registering everything I just tried to get the action working and having no luck.
Suggestions please!
Cheers,
Rob
January 12, 2014 at 10:38 pm #84908Genesis Developer
MemberDo not need to call the another action. Just remove this line
add_action( ‘genesis_before_footer’, ‘another_action’ );
and put this lineecho '<p>Some Stuff here</p>';
there. it should work.
January 12, 2014 at 11:02 pm #84911orbiterred
MemberSorry, poor example.
I'm trying to call a widget inside of the function.
I've registered the widget:
genesis_register_sidebar( array(
'id' => 'testimonialwidget1',
'name' => __( 'Testimonial Widget 1', 'themename' ),
'description' => __( 'Use this widget area to add and remove testimonials from main page', 'themename' ),
) );function testimonial_widget_1() {
genesis_widget_area( 'testimonialwidget1', array(
'before' => '<div class="testimonialwidget1">',
'after' => '</div>',
));
}add_action ( ‘genesis_before_footer’, ‘sample_action’ );
function sample_action() {
echo ‘<div class=”mydiv”>’;
add_action( ‘genesis_before_footer’, ‘testimonial_widget_1’ );
echo ‘</div>’;
}
Widget area shows up in the wp-admin but is not showing on the site.
Sorry if this is a bit muddy, been up too long.
January 12, 2014 at 11:07 pm #84912Genesis Developer
MemberRemove this
function testimonial_widget_1() { genesis_widget_area( ‘testimonialwidget1′, array( ‘before’ => ‘<div class=”testimonialwidget1″>’, ‘after’ => ‘</div>’, )); } add_action ( ‘genesis_before_footer’, ‘sample_action’ ); function sample_action() { echo ‘<div class=”mydiv”>’; add_action( ‘genesis_before_footer’, ‘testimonial_widget_1’ ); echo ‘</div>’; }
And then try this
add_action ( 'genesis_before_footer', 'testimonial_widget_1'); function testimonial_widget_1() { echo '<div class="mydiv">'; genesis_widget_area( 'testimonialwidget1′, array( 'before' => '<div class="testimonialwidget1">', 'after' => '</div>', )); echo '</div>'; }
January 12, 2014 at 11:51 pm #84918orbiterred
Memberhow about if I want to add 3 different widgetized areas? into mydiv
January 13, 2014 at 12:04 am #84919Genesis Developer
Memberthen you can do this
add_action ( 'genesis_before_footer', 'my_widgets'); function my_widgets() { echo '<div class="mydiv">'; genesis_widget_area( 'testimonialwidget1', array( 'before' => '<div class="testimonialwidget1">', 'after' => '</div>', )); genesis_widget_area( 'widget-2', array( 'before' => '<div class="widget-2">', 'after' => '</div>', )); genesis_widget_area( 'widget-3', array( 'before' => '<div class="widget-3">', 'after' => '</div>', )); echo '</div>'; }
You will register widget 2 & widget 3
January 13, 2014 at 12:15 am #84922orbiterred
MemberSeems so obvious once I see it 🙂
Thanks!!!
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.