1

I have created a child theme and recently installed woocommerce.

I have added a sidebar-shop.php file to template, which works fine when I put dummy content into it.

In my functions file I have:

function lls_woo_before_widget(){
    $content='<aside class="rightHandColumn">';
    return $content;
}
add_action('init','lls_woo_before_widget');

and in sidebar-shop.php I have:

lls_woo_before_widget();

dynamic_sidebar('secondary-aside');

The function lls_woo_before_widget doesn't seem to work but the sidebar comes in fine.

Why can't I use the function from within sidebar-shop.php and how can I (I know I could just write the code into the sidebar-shop.php file...)

Thanks

1
  • Use echo lls_woo_before_widget(); Just returning the content does not display it. Commented Feb 19, 2015 at 18:36

1 Answer 1

1

If your goal here is to wrap the secondary-aside sidebar in an <aside> tag, you should be able to do this directly in the sidebar-shop.php file like this:

?>
<aside class="rightHandColumn">
    <?php dynamic_sidebar('secondary-aside'); ?>
</aside>
<?php

As for the errors you mentioned above:

  • init is way too early to be calling this function, init hooks shouldn't generate any output since the headers haven't been sent yet, and init hooks don't modify the_content.
  • the_content is used to output posts in the loop, and won't end up in the sidebar as you expect.
  • dynamic_sidebar() prints the sidebar markup. If you wanted to act on the widgets in this sidebar as they are rendered, it has hooks
  • If you want to call a php function from one file in another php file, you need to include the file that contains the function before you attempt to call it.
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks cpilko. I suppose I was just thinking i could use the functions. But I'll just write it out as you suggest.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.