Skip to content

Instantly share code, notes, and snippets.

View palpalani's full-sized avatar

Palaniappan P palpalani

View GitHub Profile
@palpalani
palpalani / functions.php
Created June 28, 2014 07:26
WordPress - Stripping Shortcodes
There might be some cases that you need the shortcodes of the text to be omitted: You may use part of the content for a "Next Post" preview, you may have switched to a new theme and don't want to display texts of shortcodes that are not run anymore, and so on.
When that time comes, strip_shortcodes() is your friend.
Usage
There's a very good example in the Codex. Let's say that you need to strip shortcodes in the homepage but let them run in other content pages.
Here's how you should use the strip_shortcodes() function:
@palpalani
palpalani / functions.php
Created June 28, 2014 07:27
WordPress - Detecting Mobile Visitors of Your Website
Like strip_shortcodes(), wp_is_mobile() is also easy to explain: It allows you to detect users that are using mobile devices to connect to your website.
Usage
<?php
if( wp_is_mobile() ) {
// echo the "HAVE YOU TRIED OUR AWESOME MOBILE APP?" banner
} else {
// don't echo the banner
}
@palpalani
palpalani / functions.php
Created June 28, 2014 07:27
WordPress - Enqueueing Inline CSS
Ever needed to include a variable, inline style for your plugin or theme? Of course you did! Enqueueing external CSS files with WordPress' wp_enqueue_style() function (and its companions) is pretty slick but it lacks the funcionality to include inline CSS styles.
Well, at least that's what I thought before coming across the wp_add_inline_style() function.
Usage
<?php
$custom_style_file = get_template_directory_uri() . '/css/custom_style.css';
function custom_styles() {
@palpalani
palpalani / functions.php
Created June 28, 2014 07:28
WordPress - Checking If You're in the Loop
Both theme and plugin developers might need to check if their code is going to be run in the Loop or not. As the name suggests, the in_the_loop() function provides the answer easily.
Usage
<?php
if( in_the_loop() ) {
// do something loop-related
} else {
// don't do anything or display some kind of error/warning
}
@palpalani
palpalani / functions.php
Created December 27, 2014 07:34
WordPress customize upload foleder
<?php
/*
WordPress customize upload foleder path
Create a Directory within Uploads folder
*/
function mw_activate() {
$upload = wp_upload_dir();
$upload_dir = $upload['basedir'];
$upload_dir = $upload_dir . '/my_plugin_files';
@palpalani
palpalani / godaddy.txt
Created December 27, 2014 07:37
Godaddy email server sttings
Host: smtpout.secureserver.net
Port: 465
Username: your email address
Password: your_secretPassword
@palpalani
palpalani / functions.php
Created December 27, 2014 10:15
WordPress - Change default sizes for embedded content
<?php
//Adjust default sizes for embedded content
function wps_embed_size($embed_size){
if(is_single()){
$embed_size['height'] = 240;
$embed_size['width'] = 380;
}
return $embed_size;
}
add_filter('embed_defaults', 'wps_embed_size');
@palpalani
palpalani / functions.php
Created December 27, 2014 10:16
WordPress - Display comments in admin to authors own posts only
<?php
//Display comments in admin to authors own posts only
function wps_get_comment_list_by_user($clauses) {
if (is_admin()) {
global $user_ID, $wpdb;
$clauses['join'] = ", wp_posts";
$clauses['where'] .= " AND wp_posts.post_author = ". $user_ID ." AND wp_comments.comment_post_ID = wp_posts.ID";
};
return $clauses;
@palpalani
palpalani / functions.php
Created December 27, 2014 10:18
WordPress - Contact 7 form - load js, css only needed pages
<?php
/*
Contact 7 form - load js, css only needed pages
*/
add_action( 'wp_print_scripts', 'deregister_cf7_javascript', 100 );
function deregister_cf7_javascript() {
if ( !is_page(array(8, 10)) ) {
wp_deregister_script( 'contact-form-7' );
}
@palpalani
palpalani / rebuild-indexes.sql
Created April 12, 2015 05:44
Rebuild Indexes of all tables in a single MSSQL database
/*
MSSQL
-----
Rebuilds indexes on smallest tables first, allowing the maximum number of indexes to be rebuilt in the shortest amount of time.
Real time progress updates, allowing you to estimate how much time is remaining before completion.
Correctly handles multiple schemas, a common flaw in other scripts.
*/
SET NOCOUNT ON
GO