Hooks for a Theme
-
I am new to WordPress and to PHP although I have a programming background so this is probably a dumb question.
I am using WooCommerce and my theme does not officially support it. They provide documentation (pasted below) about hooking the WooCommerce into the theme, and it looks easy but I am stumped and could use a little help.
I have looked at the page.php file but I am not sure what I am looking for there. Is it a DIV id as a parameter in the remove_action and add_action. Also in what file would the last line of code go to declare the theme compatible?
Their documentation says:
non-WC theme compatibility:
Correct this by inserting a few lines in your theme’s functions.php file, First unhook the WooCommerce wrappers;
remove_action( ‘woocommerce_before_main_content’, ‘woocommerce_output_content_wrapper’, 10);
remove_action( ‘woocommerce_after_main_content’, ‘woocommerce_output_content_wrapper_end’, 10);Then hook in your own functions to display the wrappers your theme requires;
add_action(‘woocommerce_before_main_content’, ‘my_theme_wrapper_start’, 10);
add_action(‘woocommerce_after_main_content’, ‘my_theme_wrapper_end’, 10);function my_theme_wrapper_start() {
echo ‘<section id=”main”>’;
}function my_theme_wrapper_end() {
echo ‘</section>’;
}Make sure that the markup matches that of your theme. If you’re unsure of which classes or ID’s to use take a look at your theme’s page.php for a guide.
Declare WooCommerce support:
Once you’re happy that your theme fully supports WooCommerce, you should declare it in the code to hide the “Your theme does not declare WooCommerce support” message. To do so you should add the following to your theme support function;
add_theme_support( ‘woocommerce’ );
- The topic ‘Hooks for a Theme’ is closed to new replies.