Community Forums › Forums › Archived Forums › Design Tips and Tricks › Understanding genesis_setup
Tagged: genesis_setup
- This topic has 2 replies, 2 voices, and was last updated 8 years, 10 months ago by ams2.
-
AuthorPosts
-
June 20, 2015 at 9:30 am #156920ams2Member
I saw on a couple of websites people use:
add_action( 'genesis_setup', 'am_child_setup', 15 ); function cm_child_setup() {}
They put all filters, actions, and theme support code in the braces and the functions outside the braces.
I would like to know if it is OK to put the functions inside the braces instead, because I like to keep all my code together (I find it easier to manage as I'm not good with PHP).
I don't have any problems doing this. This is how I've got it:
add_action( 'genesis_setup', 'cm_child_setup', 15 ); function cm_child_setup() { // Add Viewport meta tag for mobile browsers add_theme_support( 'genesis-responsive-viewport' ); //* Unregister widget areas unregister_sidebar( 'header-right' ); // Change header background to image tag remove_action( 'wp_head', 'genesis_custom_header_style' ); add_action( 'genesis_header', 'cm_main_header', 10 ); function cm_main_header() { ?> <div class="main-header-image"> <?php echo '<a href="'.home_url().'"><img src="'.get_header_image().'" alt=""></a>'; ?> </div> <?php } //* Admin: Widgets - Unregister Genesis widgets add_action( 'widgets_init', 'cm_unregister_genesis_widgets', 20 ); function cm_unregister_genesis_widgets () { unregister_widget( 'Genesis_User_Profile_Widget' ); unregister_widget( 'Genesis_Featured_Post' ); } // admin: page and posts - remove layout options from post and pages and customize page add_action( 'init', 'cm_remove_layout_meta_boxes' ); function cm_remove_layout_meta_boxes() { remove_post_type_support( 'post', 'genesis-layouts' ); //remove_post_type_support( 'page', 'genesis-layouts' ); } add_action( 'init', 'cm_remove_scripts_meta_boxes' ); function cm_remove_scripts_meta_boxes() { remove_post_type_support( 'post', 'genesis-scripts' ); remove_post_type_support( 'page', 'genesis-scripts' ); } // Force setup genesis comments options add_filter('genesis_options', 'cm_define_genesis_setting_custom', 10, 2); function cm_define_genesis_setting_custom($options, $setting) { if($setting == GENESIS_SETTINGS_FIELD) { $options['comments_pages'] = 0; //forces on frontend (note: results are not reflected in admin, but works on frontend) $options['comments_posts'] = 1; //forces on frontend (note: results are not reflected in admin, but works on frontend) $options['trackbacks_pages'] = 0; $options['trackbacks_posts'] = 0; } return $options; } // Remove Genesis Comments and trackbacks from appearance>customize add_action( 'customize_register', 'cm_remove_customize_sections', 20 ); function cm_remove_customize_sections($wp_customize){ $wp_customize->remove_section( 'genesis_comments' ); $wp_customize->remove_section( 'genesis_breadcrumbs' ); $wp_customize->remove_section( 'genesis_archives' ); } // remove footer remove_action( 'genesis_footer', 'genesis_footer_markup_open', 5 ); remove_action( 'genesis_footer', 'genesis_do_footer' ); remove_action( 'genesis_footer', 'genesis_footer_markup_close', 15 ); // Widgets: Register before post widget area and hook genesis_register_sidebar( array( 'id' => 'before-post', 'name' => __( 'Homepage: Before Post', 'cm' ), 'description' => __( 'This will appear before your posts on your homepage.', 'cm' ), ) ); add_action( 'genesis_before_loop', 'cm_before_post' ); function cm_before_post() { if ( is_home() ) { genesis_widget_area( 'before-post', array( 'before' => '<div class="before-post widget-area">', 'after' => '</div>', ) ); } } // comments - Re-position Genesis Comment Form -reply above comments add_action( 'genesis_before_comments' , 'cm_post_type_check' ); function cm_post_type_check () { if ( is_single() ) { if ( have_comments() ) { remove_action( 'genesis_comment_form', 'genesis_do_comment_form' ); add_action( 'genesis_list_comments', 'genesis_do_comment_form' , 5 ); } } } }
Everything above is working fine.
And do I need
define( 'CHILD_THEME_NAME', 'mytheme' ); define( 'CHILD_THEME_URL', 'http://mysite.com/' );
I don't know what that is for.Also, if anyone sees any problems with my above code let me know.
Thanks in advance.
June 20, 2015 at 7:39 pm #156959neilgeeMemberThat will work ok - just a matter of preference, where you put the functions.
The CHILD_THEME_NAME and URL are more of a Genesis constant rather than WordPress, from what I can see you don't really need them - they do control some link footer output on existing SP themes but if you're building your own it is not compulsory - just as long as the theme name and parent(template) are defined in style.css
Neil Gee
WP Beaches
Coolest GuidesJune 21, 2015 at 11:55 am #157007ams2MemberThanks for your help.
-
AuthorPosts
- The topic ‘Understanding genesis_setup’ is closed to new replies.