Skip to content

Instantly share code, notes, and snippets.

View dipakcg's full-sized avatar
🎯
Focusing

Dipak C. Gajjar dipakcg

🎯
Focusing
View GitHub Profile
@dipakcg
dipakcg / functions.php
Last active May 14, 2017 10:55
WordPress - Force all scripts to footer
/* ******************
When considering performance speed, you may want to keep JS scripts organized beneath your overall page HTML.
This snippet allows most of the DOM to finish loading before running any dynamic scripts.
****************** */
function dcg_move_scripts_to_footer() {
if( !is_admin() ) {
remove_action('wp_head', 'wp_print_scripts');
remove_action('wp_head', 'wp_print_head_scripts', 9);
remove_action('wp_head', 'wp_enqueue_scripts', 1);
@dipakcg
dipakcg / functions.php
Last active June 15, 2016 15:15
WordPress - Remove menu or sub-menu page
/* ==========================================
Put the following code at the end of wp-config.php file to remove menu or sub-menu page.
========================================== */
/* *********
Line 10 will remove menu page of plugin: BackWPup
Line 11 will remove Settings menu
********* */
function dcg_custom_menu_page_removing() {
remove_menu_page( 'backwpup' );
@dipakcg
dipakcg / functions.php
Last active June 15, 2016 15:09
WordPress - Hide plugin from plugins (list) page
/* ==========================================
Put the following code at the end of wp-config.php file to hide plugin from plugins (list) page.
change line 8 with your plugin name.
========================================== */
function dcg_hide_plugin_from_dashboard() {
global $wp_list_table;
$hidearr = array('backwpup/backwpup.php');
$myplugins = $wp_list_table->items;
foreach ($myplugins as $key => $val) {
@dipakcg
dipakcg / style.less
Created May 22, 2016 07:59
Atom.io: Style Atom.io like Sublime Text on Mac
/*
* Your Stylesheet
*
* This stylesheet is loaded when Atom starts up and is reloaded automatically
* when it is changed and saved.
*
* Add your own CSS or Less to fully customize Atom.
* If you are unfamiliar with Less, you can read more about it here:
* http://lesscss.org
*/
@dipakcg
dipakcg / functions.php
Last active August 29, 2015 14:20
WordPress - Redirect failed login attempts to any location
/* Adding this snippet to the functions.php or your wordpress theme will allow you to redirect failed login attempts to any location. */
add_action( 'wp_login_failed', 'dcg_redirect_failed_login' );
function dcg_redirect_failed_login( $username ) {
$referrer = $_SERVER['HTTP_REFERER'];
if ( !empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin') ) {
wp_redirect( $referrer . '?login=failed' );
exit;
}
@dipakcg
dipakcg / functions.php
Last active August 29, 2015 14:16
WordPress - Add custom RSS feeds to dashboard
/* ========================================== */
// Add this code to theme's functions.php
// It removes the default WordPress feeds and adds your custom feeds to the admin dashboard.
/* ========================================== */
function dcg_dashboard_widgets() {
global $wp_meta_boxes;
// remove unnecessary widgets
// var_dump( $wp_meta_boxes['dashboard'] ); // use to get all the widget IDs
unset(
$wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins'],
@dipakcg
dipakcg / functions.php
Created October 31, 2014 04:38
WordPress - Replace ‘Enter Title Here’ Text
/*
Replace ‘Enter Title Here’ Text in WordPress ( http://i.imgur.com/ZAzGY6g.png )
Add the following code in theme's functions.php file.
Read more at : http://gajjar.me/1q6ADaI
*/
function wpb_change_title_text( $title ){
$screen = get_current_screen();
if ( 'movie' == $screen->post_type ) {
@dipakcg
dipakcg / search.php
Last active August 22, 2016 14:00
WordPress - Display Google Custom Search results if no posts/results found.
<?php
/* Below code will display Google Custom Search results if no posts/results found */
/* Add the below code in theme's search.php file where you want to display results from Google */
$query = get_search_query();
$query_new =str_replace(' ','%20',$query);
$url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&start=0&rsz=8&q=".$query_new;
$body = file_get_contents($url);
$json = json_decode($body);
@dipakcg
dipakcg / functions.php
Last active August 29, 2015 14:07
WordPress - Modify default role names “Administrator, Editor, Author, Contributor, Subscriber” to fit your needs
/*
Change the default role names (Administrator, Editor, Author, Contributor, Subscriber) to any custom names.
Add the following code in theme's functions.php file (edit lines 5 and 6 for custom name).
*/
function wp_change_role_name() {
global $wp_roles;
if ( ! isset( $wp_roles ) )
$wp_roles = new WP_Roles();
$wp_roles->roles['contributor']['name'] = 'Owner';
@dipakcg
dipakcg / functions.php
Created September 5, 2014 19:04
WordPress - Pass URL (with ? and &) to shortcode_atts in shortcode function
// Add following code into functions.php of WordPress theme
function willhill_text($atts) {
extract( shortcode_atts( array(
"xmlurl"=>'http://'),
$atts
)
);
$str_format = str_replace(array("&#038;","&amp;"), "&", $xmlurl);