CodeHQ

Archive for May, 2016

|

Custom post type at the top of WordPress search results

Monday, May 23rd, 2016

Paste this in to your functions.php file – this assumes your CPT is called ‘products’

add_filter( 'posts_search_orderby', function( $search_orderby ) {
    global $wpdb;
    return "{$wpdb->posts}.post_type LIKE 'products' DESC, {$search_orderby}";
});

Tags: , , , , ,
Posted in PHP, WordPress | No Comments »

Hiding WP-Login page | WordPress

Saturday, May 21st, 2016

Using the below code in your functions.php file, you would then only be able to access the WP dashboard by navigating to domain.com/wp-login.php?admin=access.

// Hiding wp-admin and wp-login.php 

function protection_for_login_page() {
$QS = '?admin=access';
$theRequest = 'http://' . $_SERVER['SERVER_NAME'] . '/' . 'wp-login.php' . '?'. $_SERVER['QUERY_STRING'];

	if ( site_url('/wp-login.php').$QS == $theRequest ) {
		echo 'Query string matches';
	} else {
		header( 'Location: http://' . $_SERVER['SERVER_NAME'] . '/' );
	}
}
add_action('login_head', 'protection_for_login_page');

Tags: , , , , , ,
Posted in PHP, WordPress | No Comments »

Adding SVG support to WordPress

Friday, May 20th, 2016

Add to functions.php

function cc_mime_types( $mimes ){
	$mimes['svg'] = 'image/svg+xml';
	return $mimes;
}
add_filter( 'upload_mimes', 'cc_mime_types' );

Tags: , , ,
Posted in PHP, WordPress | No Comments »