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 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 / 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 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 / 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 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: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: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:24
WordPress - Cloaking Email Addresses in Your Content
Have you ever needed to share an email address in your WordPress blog or website?
You most likely have, and if you ever cared about not getting caught by spam robots which crawl the web for email addresses, telephone numbers and things like that, you've searched for a solution to hide the email addresses from those tiny evil robots.
I know I have, and little did I know, there was already a core WordPress function for it: antispambot().
Usage
The usage of the function is pretty simple:
@palpalani
palpalani / wordpress-plugins.html
Last active August 29, 2015 14:00
A recommended list of must have Wordpress plugins
<ul>
<li><a href="http://www.acunetix.com/websitesecurity/wordpress-security-plugin/" target="_blank">Acunetix Wordpress Security Plugin</a>. Check <a href="http://wordpress.org/support/plugin/wp-security-scan" target="_blank">support forum</a> for any issues.</li>
<li><a href="http://wordpress.org/plugins/sucuri-scanner/" target="_blank">Sucuri Security Malware Scanner</a>. Check <a href="http://wordpress.org/support/plugin/sucuri-scanner" target="_blank">support forum</a> for any issues.</li>
<li><a href="http://wordpress.org/plugins/akismet/" target="_blank">Akismet</a>. Check <a href="http://wordpress.org/support/plugin/akismet" target="_blank">support forum</a> for any issues.</li>
<li><a href="http://www.seoegghead.com/software/wordpress-firewall.seo" target="_blank">Wordpress Firewall</a></li>
<li><a href="http://wordpress.org/plugins/crayon-syntax-highlighter/" target="_blank">Crayon Syntax Highlighter</a>. Check <a href="http://wordpress.org/support/plugin/crayon-syntax-highlighter" target=
global $db;
$upload_dir = get_misc_data('upload_directory');
$thumb_dir = get_misc_data('upload_thdirectory');
$link_id = $this->_vars['link_id'];
$sql = sprintf("SELECT file_name FROM " . table_prefix . "files WHERE file_link_id='%d' AND file_size='240x650' AND file_comment_id=0", $link_id);
if ($thumbnail = $db->get_var($sql)) {
echo "<img src='". my_pligg_base . $thumb_dir ."/$thumbnail'> ";
}