Enter your keyword

Genesis Framework

How to Disable Search Page

function fb_filter_query( $query, $error = true ) {
    
    if ( is_search() ) {
        $query->is_search = false;
        $query->query_vars[s] = false;
        $query->query[s] = false;
        
        // to error
        if ( $error == true )
            $query->is_404 = true;
    }
}

add_action( 'parse_query', 'fb_filter_query' );
add_filter( 'get_search_form', create_function( '$a', "return null;" ) );

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 Disable Search Feature in WordPress

function fb_filter_query( $query, $error = true ) {
if (is_search()){
$query->is_search = false; 
$query->query_vars[s] = false; 
$query->query[s] = false;    // to error 
if ( $error == true )  $query->is_404 = true;  
}
}
add_action( 'parse_query', 'fb_filter_query'); 
add_filter( 'get_search_form', create_function( '$a', "return null;" ) );

How to Create and using custom hooks in WordPress

Step 1: Define custom hook

function dswebsolutions_hook() {
do_action('dswebsolutions_hook');
}

Step 2: Tag your custom hook

Place the function call in the desired location within your theme template:

dswebsolutions_hook();

Step 3: Add your function

function hello_wordpress() {  	
echo '<h1>Hello WordPress!</h1>';  
}
add_action('dswebsolutions_hook', 'hello_wordpress', 7);

How to create Google Maps Shortcode

//Google Maps Shortcode
function fn_googleMaps($atts, $content = null) {
extract(shortcode_atts(array(
"width" => '640',
"height" => '480',
"src" => ''
), $atts));
return '<iframe width="'.$width.'" height="'.$height.'" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="'.$src.'&amp;output=embed"></iframe>';
}
add_shortcode("googlemap", "fn_googleMaps");
[googlemap width="200" height="200" src="[url]"]

Add Additional File Types to be Uploaded in WordPress

function dsweb_myme_types($mime_types){ 
$mime_types['svg'] = 'image/svg+xml'; //Adding svg extension
$mime_types['psd'] = 'image/vnd.adobe.photoshop'; //Adding photoshop files
return $mime_types;
}
add_filter('upload_mimes', 'dsweb_myme_types', 1, 1);

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 change WP Admin Logo

function custom_logo_wp_admin() { 
?>
<style type="text/css">
body.login div#login h1 a {
background-image: url(<?php echo get_bloginfo('stylesheet_directory') ?>/images/logo.png);  /* Logo Path*/
background-size: 220px;  /* Logo Background size */
height: 180px; /* Logo Height */
width: 180px; /*  Logo Width  */
}
</style>
<?php 
} 
add_action( 'login_enqueue_scripts', 'custom_logo_wp_admin' );

How to Replace the Widget in Genesis or WordPress

Step 1: First You will place the Unregistered Widget code in your function.php file

<?php
function remove_Featured_widget() {
  unregister_widget('Featured_Post');
}
add_action( 'widgets_init', 'remove_Featured_widget' );
?>

Step 2: Include the new widget file or function in your function.php than place Register widget function :

function Child_Featured_register_widgets() {
  register_widget( 'Child_Featured_Post' );
}
add_action( 'widgets_init', 'Child_Featured_register_widgets' );

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';
}
?>