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 Change Admin URL Without Plugin

Step 1: Configuration define in wp-config.php

define('WP_ADMIN_DIR', 'private-area');
define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH . WP_ADMIN_DIR); 

Step 2: Add a function in your theme functions.php file

add_filter('site_url',  'change_wpadmin_url', 10, 3);  
function change_wpadmin_url( $url, $path, $orig_scheme ) {
	$old_admin_url  = array( "/(wp-admin)/");
	$admin_dir = WP_ADMIN_DIR;
	$new_admin_url  = array($admin_dir);
	return preg_replace( $old_admin_url, $new_admin_url, $url, 1); 
}

Step 3: Add a line to .htaccess file

RewriteRule ^private-area/(.*) wp-admin/$1?%{QUERY_STRING} [L]

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