/* Plugin Name: WP Minify Plugin URI: http://omninoggin.com/wordpress-plugins/wp-minify-wordpress-plugin/ Description: This plugin uses the Minify engine to combine and compress JS and CSS files to improve page load time. Version: 1.2.0 Author: Thaya Kareeson Author URI: http://omninoggin.com */ /* Copyright 2009-2011 Thaya Kareeson (email : thaya.kareeson@gmail.com) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ class WPMinify { var $author_homepage = 'http://omninoggin.com/'; var $homepage = 'http://omninoggin.com/wordpress-plugins/wp-minify-wordpress-plugin/'; var $name = 'wp_minify'; var $name_dashed = 'wp-minify'; var $name_proper = 'WP Minify'; var $required_wp_version = '2.7'; var $version = '1.2.0'; var $c = null; var $debug = false; var $cache_location = 'wp-content/plugins/wp-minify/cache/'; var $url_len_limit = 2000; var $minify_limit = 50; var $buffer_started = false; var $default_exclude = array(); function WPMinify() { // initialize common functions $this->c = new WPMinifyCommon($this); // load translation $this->c->load_text_domain(); // register admin scripts add_action('admin_init', array($this->c, 'a_register_scripts')); add_action('admin_init', array($this->c, 'a_register_styles')); // check wp version add_action('admin_head', array($this->c, 'a_check_version')); // load admin menu add_action('admin_menu', array($this, 'a_menu')); // register ajax handler add_action('wp_ajax_wpm', array($this, 'a_ajax_handler')); // No need to minify admin stuff if (!is_admin() && !is_feed() && !defined('XMLRPC_REQUEST')) { // Don't minify if if user passes wp-minify-off=1 in GET parameter if (!(isset($_GET['wp-minify-off']) && $_GET['wp-minify-off'])) { add_action('init', array($this, 'pre_content'), 99999); add_action('wp_footer', array($this, 'post_content')); } // advertise hook add_action('wp_footer', array($this, 'advertise')); } } // admin functions function a_default_options() { return array( 'cache_external' => false, 'cache_interval' => 900, 'css_exclude' => array(), 'css_include' => array(), 'debug_nominify' => false, 'debug_firephp' => false, 'enable_css' => true, 'enable_js' => true, 'enable_html' => true, 'auto_base' => true, 'extra_minify_options' => '', 'js_exclude' => array(), 'js_include' => array(), 'js_in_footer' => false, 'force_https' => false, 'pretty_url' => false, 'show_link' => false, 'show_advanced' => false, 'uri_exclude' => array(), 'version' => $this->version, 'deprecated' => array( 'wp_path', 'debug', 'debug_noprettyurl' ) ); } function a_update_options() { // new options $wpm_new_options = stripslashes_deep($_POST['wpm_options_update']); // current options $wpm_current_options = get_option($this->name); // convert "on" to true and "off" to false for checkbox fields // and set defaults for fields that are left blank if (isset($wpm_new_options['show_link']) && $wpm_new_options['show_link'] == "on") $wpm_new_options['show_link'] = true; else $wpm_new_options['show_link'] = false; if (isset($wpm_new_options['enable_js'])) $wpm_new_options['enable_js'] = true; else $wpm_new_options['enable_js'] = false; if (isset($wpm_new_options['enable_css'])) $wpm_new_options['enable_css'] = true; else $wpm_new_options['enable_css'] = false; if (isset($wpm_new_options['enable_html'])) $wpm_new_options['enable_html'] = true; else $wpm_new_options['enable_html'] = false; if (isset($wpm_new_options['auto_base'])) $wpm_new_options['auto_base'] = true; else $wpm_new_options['auto_base'] = false; if (isset($wpm_new_options['cache_external'])) $wpm_new_options['cache_external'] = true; else $wpm_new_options['cache_external'] = false; if (isset($wpm_new_options['js_in_footer'])) $wpm_new_options['js_in_footer'] = true; else $wpm_new_options['js_in_footer'] = false; if (isset($wpm_new_options['pretty_url'])) $wpm_new_options['pretty_url'] = true; else $wpm_new_options['pretty_url'] = false; if (isset($wpm_new_options['debug_nominify'])) $wpm_new_options['debug_nominify'] = true; else $wpm_new_options['debug_nominify'] = false; if (isset($wpm_new_options['debug_firephp'])) $wpm_new_options['debug_firephp'] = true; else $wpm_new_options['debug_firephp'] = false; $this->a_set_minify_config($wpm_new_options['debug_nominify'], $wpm_new_options['debug_firephp']); if ( isset($wpm_new_options['force_https']) ) $wpm_new_options['force_https'] = true; else $wpm_new_options['force_https'] = false; if (strlen(trim($wpm_new_options['js_include'])) > 0) $wpm_new_options['js_include'] = $this->array_trim(split(chr(10), str_replace(chr(13), '', $wpm_new_options['js_include']))); else $wpm_new_options['js_include'] = array(); if (strlen(trim($wpm_new_options['js_exclude'])) > 0) $wpm_new_options['js_exclude'] = $this->array_trim(split(chr(10), str_replace(chr(13), '', $wpm_new_options['js_exclude']))); else $wpm_new_options['js_exclude'] = array(); if (strlen(trim($wpm_new_options['css_include'])) > 0) $wpm_new_options['css_include'] = $this->array_trim(split(chr(10), str_replace(chr(13), '', $wpm_new_options['css_include']))); else $wpm_new_options['css_include'] = array(); if (strlen(trim($wpm_new_options['css_exclude'])) > 0) $wpm_new_options['css_exclude'] = $this->array_trim(split(chr(10), str_replace(chr(13), '', $wpm_new_options['css_exclude']))); else $wpm_new_options['css_exclude'] = array(); if ( strlen(trim($wpm_new_options['uri_exclude'])) > 0 ) $wpm_new_options['uri_exclude'] = $this->array_trim(split(chr(10), str_replace(chr(13), '', $wpm_new_options['uri_exclude']))); else $wpm_new_options['uri_exclude'] = array(); // Update options foreach ($wpm_new_options as $key => $value) { $wpm_current_options[$key] = $value; } update_option($this->name, $wpm_current_options); } function a_set_advanced_options($val) { $wpm_options = get_option($this->name); $wpm_options['show_advanced'] = $val; update_option($this->name, $wpm_options); } function a_ajax_handler() { check_ajax_referer($this->name); if (isset($_POST['wpm_action'])) { if (strtolower($_POST['wpm_action']) == 'show_advanced') { $this->a_set_advanced_options(true); } elseif (strtolower($_POST['wpm_action']) == 'hide_advanced') { $this->a_set_advanced_options(false); } else { echo 'Invalid wpm_action.'; } } exit(); } function a_request_handler() { if (isset($_POST['wpm_options_update_submit'])) { check_admin_referer($this->name); $this->a_update_options(); add_action('admin_notices', array($this->c, 'a_notify_updated')); } elseif (isset($_POST['wpm_options_clear_cache_submit'])) { // if user wants to regenerate nonce check_admin_referer($this->name); $this->c->a_clear_cache(); add_action('admin_notices', array($this->c, 'a_notify_cache_cleared')); } elseif (isset($_POST['wpm_options_upgrade_submit'])) { // if user wants to upgrade options (for new options on version upgrades) check_admin_referer($this->name); $this->c->a_upgrade_options(); add_action('admin_notices', array($this->c, 'a_notify_upgraded')); } elseif (isset($_POST['wpm_options_reset_submit'])) { // if user wants to reset all options check_admin_referer($this->name); $this->c->a_reset_options(); add_action('admin_notices', array($this->c, 'a_notify_reset')); } // only check these on plugin settings page $this->c->a_check_dir_writable($this->c->get_plugin_dir().'cache/', array($this, 'a_notify_cache_not_writable')); $this->c->a_check_orphan_options(array($this, 'a_notify_orphan_options')); if ($this->c->a_check_dir_writable($this->c->get_plugin_dir().'min/config.php', array($this, 'a_notify_config_not_writable'))) { $this->a_check_minify_config(); } } function a_check_minify_config() { $fname = $this->c->get_plugin_dir().'min/config.php'; $fhandle = fopen($fname,'r'); $content = fread($fhandle,filesize($fname)); $config_modified = false; preg_match('/\/\/###WPM-CACHE-PATH-BEFORE###(.*)\/\/###WPM-CACHE-PATH-AFTER###/s', $content, $matches); $cache_path_code = $matches[1]; if (!preg_match('/\$min_cachePath.*?/', $cache_path_code)) { $content = preg_replace( '/\/\/###WPM-CACHE-PATH-BEFORE###(.*)\/\/###WPM-CACHE-PATH-AFTER###/s', "//###WPM-CACHE-PATH-BEFORE###\n".'$min_cachePath = \''.$this->c->get_plugin_dir()."cache/';\n//###WPM-CACHE-PATH-AFTER###", $content); $config_modified = true; } preg_match('/\/\/###WPM-CACHE-AGE-BEFORE###(.*)\/\/###WPM-CACHE-AGE-AFTER###/s', $content, $matches); $cache_age_code = $matches[1]; if (!preg_match('/\$min_serveOptions\[\'maxAge\'].*?/', $cache_age_code)) { $content = preg_replace( '/\/\/###WPM-CACHE-AGE-BEFORE###(.*)\/\/###WPM-CACHE-AGE-AFTER###/s', "//###WPM-CACHE-AGE-BEFORE###\n".'$min_serveOptions[\'maxAge\'] = 2592000;'."\n//###WPM-CACHE-AGE-AFTER###", $content); $config_modified = true; } if ($config_modified) { $this->a_notify_modified_minify_config(); } $fhandle = fopen($fname,"w"); fwrite($fhandle,$content); fclose($fhandle); } function a_set_minify_config($nominify = false, $firephp = false) { if ($nominify) { $nominify = 'true'; } else { $nominify = 'false'; } if ($firephp) { $firephp = 'true'; } else { $firephp = 'false'; } $fname = $this->c->get_plugin_dir().'min/config.php'; $fhandle = fopen($fname,'r'); $content = fread($fhandle,filesize($fname)); $content = preg_replace( '/\/\/###WPM-DEBUG-FLAG-BEFORE###(.*)\/\/###WPM-DEBUG-FLAG-AFTER###/s', "//###WPM-DEBUG-FLAG-BEFORE###\n".'$min_allowDebugFlag = '.$nominify.";\n//###WPM-DEBUG-FLAG-AFTER###", $content); $content = preg_replace( '/\/\/###WPM-ERROR-LOGGER-BEFORE###(.*)\/\/###WPM-ERROR-LOGGER-AFTER###/s', "//###WPM-ERROR-LOGGER-BEFORE###\n".'$min_errorLogger = '.$firephp.";\n//###WPM-ERROR-LOGGER-AFTER###", $content); $fhandle = fopen($fname,"w"); fwrite($fhandle,$content); fclose($fhandle); } function a_notify_cache_not_writable() { $this->c->a_notify( sprintf('%s: %s', __('Cache directory is not writable. Please grant your server write permissions to the directory', $this->name), $this->c->get_plugin_dir().'cache/'), true); } function a_notify_config_not_writable() { $this->c->a_notify( sprintf('%s: %s', __('Minify Engine config.php is not writable. Please grant your server write permissions to file', $this->name), $this->c->get_plugin_dir().'min/config.php')); } function a_notify_orphan_options() { $this->c->a_notify( sprintf('%s', __('Some option settings are missing (possibly from plugin upgrade).', $this->name))); } function a_notify_modified_minify_config() { $this->c->a_notify(__('Minify Engine config.php was configured automatically.', $this->name)); } function a_menu() { $options_page = add_options_page($this->name_proper, $this->name_proper, 'manage_options', 'wp-minify', array($this, 'a_page')); add_action('admin_head-'.$options_page, array($this, 'a_request_handler')); add_action('admin_print_scripts-'.$options_page, array($this->c, 'a_enqueue_scripts')); add_action('admin_print_styles-'.$options_page, array($this->c, 'a_enqueue_styles')); } function a_page() { $wpm_options = get_option($this->name); printf('

%s

%s |  %s
', __('WP Minify Options', $this->name), __('General Configuration', $this->name), __('Documentation', $this->name) ); printf('
'); if (isset($_GET['wpm-page'])) { if ($_GET['wpm-page'] || !$_GET['wpm-page']) { require_once('options-generic.php'); } } else { require_once('options-generic.php'); } printf('
'); // omni_admin_main require_once('options-sidebar.php'); printf('
'); // wrap } // admin_page() // other functions function fetch_and_cache($url, $cache_file) { $ch = curl_init(); $timeout = 5; // set to zero for no timeout curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt ($ch, CURLOPT_USERAGENT, 'WP-Minify'); $content = curl_exec($ch); curl_close($ch); if ($content) { if (is_array($content)) { $content = implode($content); } // save cache file $fh = fopen($cache_file, 'w'); if ($fh) { fwrite($fh, $content); fclose($fh); } else { // cannot open for write. no error b/c something else is probably writing to the file. } return $content; } else { printf( '%s: '.$url.'. %s
', __('Error: Could not fetch and cache URL'), __('You might need to exclude this file in WP Minify options.') ); return ''; } } function refetch_cache_if_expired($url, $cache_file) { $wpm_options = get_option($this->name); $cache_file_mtime = filemtime($cache_file); if ((time() - $cache_file_mtime) > $wpm_options['cache_interval']) { $this->fetch_and_cache($url, $cache_file); } } function tiny_filename($str) { $f = __FILE__; // no fancy shortening for Windows return ('/' === $f[0]) ? strtr(base64_encode(md5($str, true)), '+/=', '-_(') : md5($str); } function array_trim($arr, $charlist=null) { foreach ($arr as $key => $value) { if (is_array($value)) $result[$key] = array_trim($value, $charlist); else $result[$key] = trim($value, $charlist); } return $result; } function check_and_split_url($url, $latest_modified = 0) { $url_chunk = explode('?f=', $url); $base_url = array_shift($url_chunk); $files = explode(',', array_shift($url_chunk)); $num_files = sizeof($files); if ($this->url_needs_splitting($url, $files)) { $first_half = $this->check_and_split_url($base_url . '?f=' . implode(',', array_slice($files, 0, $num_files/2)), $latest_modified); $second_half = $this->check_and_split_url($base_url . '?f=' . implode(',', array_slice($files, $num_files/2)), $latest_modified); return $first_half + $second_half; } else { $wpm_options = get_option($this->name); // append &debug if we need to if ($wpm_options['debug_nominify']) { $debug_string = '&debug=true'; } else { $debug_string = ''; } // append base directory if needed $base = $this->get_base(); if ($base != '') { $base_string = '&b='.$base; } else { $base_string = ''; } // get rid of any base directory specification in extra options $extra_minify_options = preg_replace('/(&|&|\b)b=[^&]*/', '', trim($wpm_options['extra_minify_options'])); if (trim($extra_minify_options) != '') { $extra_string = '&'.$extra_minify_options; } else { $extra_string = ''; } // append last modified time $latest_modified_string = '&m='.$latest_modified; return array($base_url . '?f=' . implode(',', $files) . $debug_string . $base_string . $extra_string . $latest_modified_string); } } function fetch_content($url, $type = '') { $cache_file = $this->c->get_plugin_dir().'cache/'.md5($url).$type; $content = ''; if (file_exists($cache_file)) { // check cache expiration $this->refetch_cache_if_expired($url, $cache_file); $fh = fopen($cache_file, 'r'); if ($fh && filesize($cache_file) > 0) { $content = fread($fh, filesize($cache_file)); fclose($fh); } else { // cannot open cache file so fetch it $content = $this->fetch_and_cache($url, $cache_file); } } else { // no cache file. fetch from internet and save to local cache $content = $this->fetch_and_cache($url, $cache_file); } return $content; } function local_version($url) { $site_url = trailingslashit(get_option('siteurl')); $url = str_replace($site_url, '', $url); // relative paths only for local urls $url = preg_replace('/^\//', '', $url); // strip front / if any $url = preg_replace('/\?.*/i', '', $url); // throws away parameters, if any return $url; } function is_external($url, $localize=true) { if ($localize) { $url = $this->local_version($url); } if (substr($url, 0, 4) != 'http' && (substr($url, -3, 3) == '.js' || substr($url, -4, 4) == '.css')) { return false; } else { return true; } } function get_js_location($src) { if ($this->debug) echo 'Script URL:'.$src."
\n"; $script_path = $this->local_version($src); if ($this->is_external($script_path, false)) { // fetch scripts if necessary $this->fetch_content($src, '.js'); $location = $this->cache_location . md5($src) . '.js'; if ($this->debug) echo 'External script detected, cached as:'. md5($src) . "
\n"; } else { // if script is local to server $location = $script_path; if ($this->debug) echo 'Local script detected:'.$script_path."
\n"; } return $location; } function get_css_location($src) { if ($this->debug) echo 'Style URL:'.$src."
\n"; $css_path = $this->local_version($src); if ($this->is_external($css_path, false)) { // fetch scripts if necessary $this->fetch_content($src, '.css'); $location = $this->cache_location . md5($src) . '.css'; if ($this->debug) echo 'External css detected, cached as:'. md5($src) . "
\n"; } else { $location = $css_path; // if css is local to server if ($this->debug) echo 'Local css detected:'.$css_path."
\n"; } return $location; } function url_needs_splitting($url, $locations) { if ($url > $this->url_len_limit || count($locations) > $this->minify_limit) { return true; } else { return false; } } function build_minify_urls($locations, $type) { $wpm_options = get_option($this->name); $minify_url = $this->c->get_plugin_url().'min/?f='; if ($wpm_options['force_https'] && $_SERVER["HTTPS"] == "on") { $minify_url = preg_replace('/^http:\/\//', 'https://', $minify_url); } $minify_url .= implode(',', $locations); $latest_modified = $this->get_latest_modified_time($locations); $minify_urls = $this->check_and_split_url($minify_url, $latest_modified); if ($wpm_options['pretty_url']) { return $this->get_cached_minify_urls($minify_urls, $type); } else { return $minify_urls; } } function get_cached_minify_urls($urls, $type) { $wpm_options = get_option($this->name); $cached_urls = array(); foreach ($urls as $url) { $cache_file = $this->c->get_plugin_dir().'cache/'.md5($url).$type; if (file_exists($cache_file)) { // check cache expiration $this->refetch_cache_if_expired($url, $cache_file); $fh = fopen($cache_file, 'r'); if ($fh && filesize($cache_file) > 0) { $content = fread($fh, filesize($cache_file)); fclose($fh); } else { // cannot open cache file so fetch it $this->fetch_and_cache($url, $cache_file); } } else { // no cache file. fetch it $this->fetch_and_cache($url, $cache_file); } $cache_url = $this->c->get_plugin_url().'cache/'.md5($url).$type.'?m='.filemtime($cache_file); $cached_urls[] = $cache_url; } return $cached_urls; } function get_base_from_minify_args() { $wpm_options = get_option($this->name); if (!empty($wpm_options['extra_minify_options'])) { if (preg_match('/\bb=([^&]*?)(&|$)/', trim($wpm_options['extra_minify_options']), $matches)) { return rtrim(trim($matches[1]), '\\/'); } } return ''; } function get_base_from_siteurl() { $site_url = trailingslashit(get_option('siteurl')); return rtrim(preg_replace('/^https?:\/\/.*?\//', '', $site_url), '\\/'); } function get_base() { $base_from_min_args = $this->get_base_from_minify_args(); if ($base_from_min_args != '') { return $base_from_min_args; } $wpm_options = get_option($this->name); if ($wpm_options['auto_base']) { return $this->get_base_from_siteurl(); } else { return ''; } } function get_latest_modified_time($locations = array()) { $latest_modified = 0; if (!empty($locations)) { $base_path = trailingslashit($_SERVER['DOCUMENT_ROOT']); $base_path .= trailingslashit($this->get_base()); foreach ($locations as $location) { $path = $base_path.$location; $mtime = filemtime($path); if ($latest_modified < $mtime) { $latest_modified = $mtime; } } } return $latest_modified; } function extract_css($content) { $wpm_options = get_option($this->name); $css_locations = array(); preg_match_all('/]*?)>/i', $content, $link_tags_match); foreach ($link_tags_match[0] as $link_tag) { if (strpos(strtolower($link_tag), 'stylesheet')) { // check CSS media type if (!strpos(strtolower($link_tag), 'media=') || preg_match('/media=["\'](?:["\']|[^"\']*?(all|screen)[^"\']*?["\'])/', $link_tag) ) { preg_match('/href=[\'"]([^\'"]+)/', $link_tag, $href_match); if ($href_match[1]) { // include it if it is in the include list $include = false; $inclusions = $wpm_options['css_include']; foreach ($inclusions as $include_pat) { $include_pat = trim($include_pat); if (strlen($include_pat) > 0 && strpos($src_match[1], $include_pat) !== false) { $include = true; break; } } if (!$include) { // support external files? if (!$wpm_options['cache_external'] && $this->is_external($href_match[1])) { continue; // skip if we don't cache externals and this file is external } // do not include anything in excluded list $skip = false; $exclusions = array_merge($this->default_exclude, $wpm_options['css_exclude']); foreach ($exclusions as $exclude_pat) { $exclude_pat = trim($exclude_pat); if (strlen($exclude_pat) > 0 && strpos($href_match[1], $exclude_pat) !== false) { $skip = true; break; } } if ($skip) continue; } $content = str_replace($link_tag . '', '', $content); $content = str_replace($link_tag, '', $content); $css_locations[] = $this->get_css_location($href_match[1]); } } } } $css_locations = array_unique($css_locations); return array($content, $css_locations); } function inject_css($content, $css_locations) { if (count($css_locations) > 0) { $wpm_options = get_option($this->name); // build minify URLS $css_tags = ''; $minify_urls = $this->build_minify_urls($css_locations, '.css'); foreach ($minify_urls as $minify_url) { $minify_url = apply_filters('wp_minify_css_url', $minify_url); // Allow plugins to modify final minify URL $css_tags .= ""; } $matches = preg_match('//', $content); if ($matches) { $content = preg_replace('//', "$css_tags", $content, 1); // limit 1 replacement } else { // HTML5 has
tags so account for those in regex $content = preg_replace('/|\s[^>]*?>)/', "\\0\n$css_tags", $content, 1); // limit 1 replacement } } return $content; } function extract_conditionals($content) { preg_match_all('//is', $content, $conditionals_match); $content = preg_replace('//is', '###WPM-CSS-CONDITIONAL###', $content); $conditionals = array(); foreach ($conditionals_match[0] as $conditional) { $conditionals[] = $conditional; } return array($content, $conditionals); } function inject_conditionals($content, $conditionals) { while (count($conditionals) > 0 && strpos($content, '###WPM-CSS-CONDITIONAL###')) { $conditional = array_shift($conditionals); $content = preg_replace('/###WPM-CSS-CONDITIONAL###/', $conditional, $content, 1); } return $content; } function extract_js($content) { $wpm_options = get_option($this->name); $js_locations = array(); preg_match_all('/]*?)><\/script>/i', $content, $script_tags_match); foreach ($script_tags_match[0] as $script_tag) { if (strpos(strtolower($script_tag), 'text/javascript') !== false) { preg_match('/src=[\'"]([^\'"]+)/', $script_tag, $src_match); if ($src_match[1]) { // include it if it is in the include list $include = false; $inclusions = $wpm_options['js_include']; foreach ($inclusions as $include_pat) { $include_pat = trim($include_pat); if (strlen($include_pat) > 0 && strpos($src_match[1], $include_pat) !== false) { $include = true; break; } } if (!$include) { // support external files? if (!$wpm_options['cache_external'] && $this->is_external($src_match[1])) { continue; // skip if we don't cache externals and this file is external } // do not include anything in excluded list $skip = false; $exclusions = array_merge($this->default_exclude, $wpm_options['js_exclude']); foreach ($exclusions as $exclude_pat) { $exclude_pat = trim($exclude_pat); if (strlen($exclude_pat) > 0 && strpos($src_match[1], $exclude_pat) !== false) { $skip = true; break; } } if ($skip) continue; } $content = str_replace($script_tag, '', $content); $js_locations[] = $this->get_js_location($src_match[1]); } } } $js_locations = array_unique($js_locations); return array($content, $js_locations); } function inject_js($content, $js_locations) { if (count($js_locations) > 0) { // build minify URLS $js_tags = ''; $minify_urls = $this->build_minify_urls($js_locations, '.js'); foreach ($minify_urls as $minify_url) { $minify_url = apply_filters('wp_minify_js_url', $minify_url); // Allow plugins to modify final minify URL $js_tags .= ""; } $matches = preg_match('//', $content); if ($matches) { $content = preg_replace('//', "$js_tags", $content, 1); // limit 1 replacement } else { $wpm_options = get_option($this->name); if ($wpm_options['js_in_footer']) { $content = preg_replace('/<\/body>/', "$js_tags\n", $content, 1); // limit 1 replacement } else { // HTML5 has
tags so account for those in regex $content = preg_replace('/|\s[^>]*?>)/', "\\0\n$js_tags", $content, 1); // limit 1 replacement } } } return $content; } function pre_content() { $wpm_options = get_option($this->name); if ($wpm_options['uri_exclude'] && count($wpm_options['uri_exclude'])) { foreach ($wpm_options['uri_exclude'] as $exclude_pat) { $exclude_pat = trim($exclude_pat); if (strlen($exclude_pat) > 0 && strpos($_SERVER['REQUEST_URI'], $exclude_pat) !== false) { return; } } } ob_start(array($this, 'modify_buffer')); // variable for sanity checking $this->buffer_started = true; } function modify_buffer($buffer) { $wpm_options = get_option($this->name); // if we do not want to force http to https then we need to exclude https if (!($wpm_options['force_https'] && $_SERVER["HTTPS"] == "on")) { $this->default_exclude[] = 'https://'; } // minify JS if ($wpm_options['enable_js']) { list($buffer, $js_locations) = $this->extract_js($buffer); $buffer= $this->inject_js($buffer, $js_locations); } // minify CSS (make sure to exclude CSS conditionals) if ($wpm_options['enable_css']) { list($buffer, $conditionals) = $this->extract_conditionals($buffer); list($buffer, $css_locations) = $this->extract_css($buffer); $buffer = $this->inject_css($buffer, $css_locations); $buffer = $this->inject_conditionals($buffer, $conditionals); } // get rid of empty lines $buffer = preg_replace('/\s*(\r?\n)(\r?\n)*/', '$1', $buffer); // minify HTML if ($wpm_options['enable_html']) { if (!class_exists('Minify_HTML')) { require_once('min/lib/Minify/HTML.php'); } $buffer = Minify_HTML::minify($buffer); } $buffer = apply_filters('wp_minify_content', $buffer); // allow plugins to modify buffer return $buffer; } function post_content() { // sanity checking if ($this->buffer_started) { ob_end_flush(); } } function advertise() { $wpm_options = get_option($this->name); if ($wpm_options['show_link']) { printf("

Page optimized by $this->name_proper WordPress Plugin

"); } } } // class WPMinify require_once('common.php'); require_once('http_build_url.php'); $wp_minify = new WPMinify(); ?> Best SEO Techniques 2013 | Techlato

Best SEO Techniques 2013

If you ever wondered, What are the best SEO Techniques 2013 ( link building , tags, directories, etc..) You are in trouble. No SEO Technique alone can be considered as the best. The companies are devoting to know SEO, so they seek to diversify SEO techniques to develop.

Best SEO Techniques 2013

Best SEO Techniques 2013

In line with the comments about the SEO trends , now it’s time to see the recommended techniques.

1. Generate Quality Content

Creating quality content is not an easy task. Companies are designing content strategies, and for larger companies, the strategies are rather complex.

Also Check – Does Blog Commenting Help SEO?

Imagine a company that offers dozens of products in each of these different types, sizes, styles. Each offering a different experience to the customer. What is the best way that we can optimize our content? Here are some ideas to keep in mind:

  • The Content of a Page should not be too long
  • If you distribute content in parts, it must be consistent
  • Note the keywords, but do not abuse. Should be used naturally in the content.
  • Use H tags to distribute your articles better
  • Use the bold text and internal links
  • Beware of duplicate content
  • Links to external sites with relevant content
  • Update content for your web site continuously

Also Read : 5 Tips to Optimize your WordPress Blog for SEO

2. Build Backlinks

There are many ways to generate inbound links (link building). The most common are through social networks (Delicious, Twitter, Facebook, etc.), Forums, blogs, etc.. And even writing articles on quality sites or paying to publish one with a link to our site. But leaving that aside, there are some tips you should keep in mind:

Must be unique content

If you’re writing a guest post on a blog, do not repeat the same content in another. Many people were posting the same items in different sites to generate inbound links.

Conclusion: Your inbound links should come from unique content.

Vary Link Text

The Anchor Text should not be the same. A common practice of spammers is to repeat the same phrase to link.

What is not normal or natural. If you want generate the link value to your website, you should make sure that your text is within the context of the article or piece of content that is being treated. This is very important, especially now that the search engines analyze contents semantically .

Also Read : SEO is not the Solution to your Problems

3. Enlarge Traffic Sources (Bing)

Currently Techlato gets about 10-15% of search traffic from Bing and I’m sure the potential is much greater. Moreover, the mere fact that our SEO strategy depends on a single search engine.

Of course, Google is the main search engine, but we must never neglect the optimization for the other search engines. Among some tips to keep in mind to optimize our best seo techniques for Bing and Yahoo , we have:

  • Emphasis on the label title: Bing is mindful of the keywords used in the title of the page, not only the H1 article.
  • This is not confirmed, but according to experts, usually Bing values better pages with over 300 words in your content.
  • The links are so important to Google &  Bing.
  • Bing recommends you use Meta Tags for each page only
  • Use schema.org markup
  • Use friendly URLs.
  • Use the tools that Bing offers: Bing Webmaster Tools.

Remember to optimize for Bing & Yahoo.

Plus: Optimize for Local Search

Buying Offline by Searching Online has been a growing pratice. So if you have the website of a small business, you must focus on capturing local traffic. Here are some tips to keep in mind:

  • Displays your correct address and phone number.
  • Your website must be optimized for mobile devices, and if not optimized, at least should not have breaks.
  • Use a domain local extension.
  • Associate your country domain in Google webmaster tools.
  • Use a local hosting.
  • Use regional language properly written. For example, not just write an article for one of Argentina to Mexico.
  • Get inbound links from sites with local domain extension.
  • It is also advisable to have links to local directories like the Yellow Pages of your country.

Also Read : How to measure the Success of your Blog

Don’t forget to share this tutorial on Google+ to all your friends. Use the button below to +1 this tutorial and share on Google+.


I hope these tips on Best SEO Techniques 2013 will be useful. If you disagree with any or if you feel that I have omitted other, I invite you to leave a comment. And in any case, to share it.

Incoming search terms:

  • seo techniques 2013
  • seo techniques
  • latest seo techniques 2013
  • new seo techniques 2013
  • best seo techniques 2013

About Nagaraj

Hey! My name is Nagaraj. If you like the article, do not forget to subscribe to the page. You can read more about the author , or get in touch with me . My profile on Facebook | Google+

25 Responses to Best SEO Techniques 2013

  1. mplysiak February 19, 2013 at 11:19 am #

    Excellent article. I would also like to add that many SEO’s do not take the time to comment on blogs with a low page rank. If I like the content of a blog and find it useful it is always worth commenting on and sharing. It may not be ranked now but over time it can turn into a very valuable link!
    mplysiak recently posted…My Google Back Links Disappeared from Webmaster Tools OvernightMy Profile

    • Nagaraj February 19, 2013 at 6:13 pm #

      I agree with you… A blog may not be ranked now, but if we follow some simple steps and have patience then definitely it will come up :) Glad you liked my article :) Keep visiting…!
      Nagaraj recently posted…Envasi0n Updated to version 1.1 with Bug FixesMy Profile

  2. vinay February 22, 2013 at 10:23 pm #

    good article bro!! really useful for bloggers… as i am new to blogging looking for some best seo tips and tricks…i found your article.. its helpful for me…!!
    thank you..
    vinay recently posted…How to Disable Dual Boot on Start UpMy Profile

    • Nagaraj February 22, 2013 at 10:44 pm #

      Thanks Vinay! More posts to come… Stay Tuned :)

  3. Osvin webSolutions February 25, 2013 at 1:31 pm #

    Thank You so much for giving us such a wonderful Blog….Your Blog is really very useful for us. Please give some more such kind of Articles……….Once again Thank You..:-)

  4. Willard February 27, 2013 at 11:24 pm #

    Thank you, I’ve recently been looking for information about this subject for a long time and yours is the best I’ve
    found out so far. But, what concerning the conclusion?
    Are you positive about the source?

  5. Nishant March 15, 2013 at 12:56 pm #

    Really Nice job.. i am agree with mplysiak …Content is the king. good content always get rewarded…
    Nishant recently posted…Amazing OS Back track 5 R3My Profile

  6. maruf March 20, 2013 at 12:25 am #

    Really great article about seo techniques. I will follow this techniques in my blog.
    My blog is seo techniques
    maruf recently posted…How to verify website with PinterestMy Profile

  7. Aitor March 20, 2013 at 5:03 am #

    Thank you for the post. Gave me some ideas to improve my strategies. I use some or a combination of these techniques and I totally agree, quality content is what drives blogs, and content is king.
    Aitor recently posted…Off Page SEO TechniquesMy Profile

  8. Sachin March 25, 2013 at 10:52 am #

    Thanks for this Great article brother :) I am trying my best to improve SEO on my site !!
    Sachin recently posted…What is the best way of SEO practices for URL redirecting ?My Profile

    • Nagaraj March 25, 2013 at 9:47 pm #

      Thanks Sachin… Good Luck for you :-)

  9. Jamal March 27, 2013 at 3:53 am #

    I am very much frustrated about the google rankings. I dont know how we have to rank sites to the top 1 google page. It was easy 3 years back but with time things changed.

    I use the site dropmylink.com to find related links. 😉

    Its not my site so no spam!

  10. Swapnil Kolhe April 1, 2013 at 3:16 pm #

    thank you for this post . . it gaves me new idea for optimizing my own site

    thanx bro

    • Nagaraj April 1, 2013 at 7:04 pm #

      Good Luck with your Site Bro :-)

  11. Rose April 11, 2013 at 6:06 pm #

    Good and simple article.

  12. PrIyAnGsHu April 11, 2013 at 7:04 pm #

    Great tips Nagaraj. I think we must surely vary the anchor texts while building backlinks to oru sites, either we will surely get hit by Google Panda.
    PrIyAnGsHu recently posted…How to Recover Deleted Data from Google DriveMy Profile

    • Nagaraj April 11, 2013 at 11:20 pm #

      Hey PrlyAnGsHu… Google is very serious about this issue and Panda is after us 😀

  13. Khelmart April 13, 2013 at 4:08 pm #

    Nice Information , I think contents will be the king in year 2013 as Google or any SE will like to see new and fresh content to be display on web search. Promoting the web content in positive way is equally important and on this front how effectively webmaster are utilizing the social media is noteworthy.
    Anyways great job and keep it up in future.

  14. Neha Gupta April 17, 2013 at 11:10 am #

    Good article! Can you please share some more tips for local optimization of the website. I m working on regional domains and now using hcard. Now please share how to get relevant traffic from associated region.

  15. George@ Webmasters Forum May 7, 2013 at 7:48 pm #

    Thank you Nagaraj for this post, i really enjoy this post because the post is not too long & content is point on subject properly. Everyday i spend sometime to read seo post on different techniques, for me the most impressive point is “Enlarge Traffic Sources”, i really like this point.

  16. Jeremy May 9, 2013 at 6:43 am #

    Hello very cool site!! Guy .. Beautiful .
    . Amazing .. I’ll bookmark your website and take the feeds additionally? I’m happy to find a lot of useful info
    right here in the post, we’d like work out extra techniques in this regard, thank you for sharing. . . . . .
    Jeremy recently posted…JeremyMy Profile

  17. Sanjay May 10, 2013 at 6:37 pm #

    Thanks for this SEO Techniques Really helpfull to all nice
    Sanjay recently posted…Top Best laptops 2013My Profile

Trackbacks/Pingbacks

  1. Steps to Improved SEO | Strategic Social Media - March 11, 2013

    […] http://www.techlato.com/best-seo-techniques-2013/ […]

  2. Best SEO Techniques 2013 | SEO Expert, Lahore - Pakistan | Nabeel Nazir 0332-4427189 - May 8, 2013

    […] Source:http://www.techlato.com/best-seo-techniques-2013/ […]

Leave a Reply

CommentLuv badge

Please support the site
By clicking any of these buttons you help our site to get better