Enter your keyword

Genesis Theme

How to add radio button Metabox in WordPress Custom and Default Post Types

add_action( 'add_meta_boxes', 'post_disable_enable' );
function post_disable_enable() {
add_meta_box('post_disable_enable', 'Post Disable Enable', 'post_disable_enable_meta', 'post' );
}
function post_disable_enable_meta( $post ) {
	wp_nonce_field( 'post_disable_enable', 'post_disable_enable_nonce' );
	$value = get_post_meta( $post->ID, 'post_disable_enable', true );
	echo '<input type="radio" name="post_disable_enable" value="disable" ';
    	if($value=='disable') {
			echo 'checked';
		}
	'> Disable<br/>';
	echo '<input type="radio" name="post_disable_enable" value="enable" ';
		if($value=='enable') {
			echo 'checked';
		}
	echo '> Enable<br/>';
  }
  
add_action( 'save_post', 'disable_enable_save_meta_box_data' );
function disable_enable_save_meta_box_data( $post_id ) {
	// Check if our nonce is set.

	if ( !isset( $_POST['post_disable_enable_nonce'] ) ) {
  	return;
  	}
	// Verify that the nonce is valid.
	if ( !wp_verify_nonce( $_POST['post_disable_enable_nonce'], 'post_disable_enable' ) ) {
	return;
	}
	// If this is an autosave, our form has not been submitted, so we don't want to do anything.
	if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
  	return;
  	}
  	// Check the user's permissions.
	if ( !current_user_can( 'edit_post', $post_id ) ) {
	return;
	}
  	// Sanitize user input.
  	$new_meta_value = ( isset( $_POST['post_disable_enable'] ) ? sanitize_html_class( $_POST['post_disable_enable'] ) : '' );
	// Update the meta field in the database.
	update_post_meta( $post_id, 'post_disable_enable', $new_meta_value );
  }

How to Add Additional Image Sizes in WordPress

WordPress automatically creates several image sizes when you upload an image. You can also create additional image sizes to use in your theme. Add this code your theme's functions file.

add_image_size( 'sidebar-thumb', 120, 120, true ); // Hard Crop Mode  
  add_image_size( 'homepage-thumb', 220, 180 ); // Soft Crop Mode  
  add_image_size( 'singlepost-thumb', 590, 9999 ); // Unlimited Height Mode

You can display an image size in anywhere in your theme using this code

the_post_thumbnail( 'homepage-thumb' );

How to Remove Default Genesis Footer widgets

<?php /* Remove Genesis Footer Widgets in Admin Widgets Area */
 remove_theme_support( 'genesis-footer-widgets', 3 ); ?>
<?php
/* Remove Genesis Footer Widgets in Front end */
remove_action( 'genesis_before_footer', 'genesis_footer_widget_areas' );
?>

How to Add new custom favicon icon in Genesis

<?php 
/** Add new custom favicon icon in Genesis */
add_filter( 'genesis_pre_load_favicon', 'custom_favicon' );
function custom_favicon( $favicon_url ) {
    return get_stylesheet_directory_uri().'/images/favicon.ico';
}
?>

Registering the Widget Area in Genesis

The first step is to register the before header widget area through your functions file. Use the code below to do accomplish that:

<?php
//* Register before header widget area
genesis_register_sidebar( array(
'id' => 'before-header',
'name' => __( 'Before Header', 'theme-name' ),
'description' => __( 'This is the before header widget area.', 'theme-name' ),
) ); 
?>

Hooking the Widget Area

Now that you have registered the before header widget area, you need to place that onto a hook that resides before the site header markup.

The code below will do that for you:

<?php
//* Hook before header widget area before site header
add_action( 'genesis_before_header', 'bg_before_header_widget_area' );
function bg_before_header_widget_area() {
genesis_widget_area( 'before-header', array(
'before' => '<div class="before-header widget-area"><div class="wrap">',
'after' => '</div></div>',
) );
} ?>