Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Dipak C. Gajjar dipakcg

🎯
Focusing
View GitHub Profile
@dipakcg
dipakcg / functions.php
Created Sep 5, 2014
WordPress - Pass URL (with ? and &) to shortcode_atts in shortcode function
View functions.php
// 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("&","&"), "&", $xmlurl);
@dipakcg
dipakcg / functions.php
Last active Aug 29, 2015
WordPress - Modify default role names “Administrator, Editor, Author, Contributor, Subscriber” to fit your needs
View functions.php
/*
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 / search.php
Last active Aug 22, 2016
WordPress - Display Google Custom Search results if no posts/results found.
View search.php
<?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
Created Oct 31, 2014
WordPress - Replace ‘Enter Title Here’ Text
View functions.php
/*
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 / functions.php
Last active Aug 29, 2015
WordPress - Add custom RSS feeds to dashboard
View functions.php
/* ========================================== */
// 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
Last active Aug 29, 2015
WordPress - Redirect failed login attempts to any location
View functions.php
/* 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 / style.less
Created May 22, 2016
Atom.io: Style Atom.io like Sublime Text on Mac
View style.less
/*
* 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 Jun 15, 2016
WordPress - Hide plugin from plugins (list) page
View functions.php
/* ==========================================
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 / functions.php
Last active Jun 15, 2016
WordPress - Remove menu or sub-menu page
View functions.php
/* ==========================================
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 May 14, 2017
WordPress - Force all scripts to footer
View functions.php
/* ******************
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);