This plugin hasn’t been updated in years, but it still seems to work for the most part.
Anyway, the plugin has you add code to the header to get it to work, however this isn’t really necessary as long as your theme is following wordpress coding standards and using wp_head
(every theme on www.ads-software.com). This is all you should have to do since technically ti would be the same as adding to the beginning and end of the head>.
add_action('wp_head', function() {
if (function_exists('orderStyleJS'))
orderStyleJS( 'start' );
}, -1);
add_action('wp_head', function() {
if (function_exists('orderStyleJS'))
orderStyleJS( 'end' );
}, PHP_INT_MAX);
You can probably just add this to the plugin itself since it doesn’t look like it will be getting updates anytime soon.
https://www.ads-software.com/plugins/performance-optimization-order-styles-and-javascript/
]]>Hi
I installed the plugin but both my Huge IT slider and zoom plugins stop working. The sliders are visible but they do not move and the zoom fails to work when the mouse passes over a product image. Any ideas?
Thanks
Regards
Jeremy
https://www.ads-software.com/plugins/performance-optimization-order-styles-and-javascript/
]]>Hi,
When I have Google Universal Analytics code in my head, together with this plugin installed, the Analytics code stops tracking.
The plugin seems to be adding additional codes to the Analtyics one.
This happens whether I install the Analytics code manually or using Joost Analytics Plugin. Moving the placement of the Analtyics code in the head does not help.
Otherwise this plugin works great at re-ordering the scripts.
How can we solve this critical issue?
https://www.ads-software.com/plugins/performance-optimization-order-styles-and-javascript/
]]>It was writing the <script> tags after the </html>, so I modified it:
<?php
/*
Plugin Name: Performance Optimization: Order Styles and Javascript
Plugin URI: https://www.satya-weblog.com/?p=2392
Description: Performance optimization tips: Make CSS at the top and scripts at the bottom in HTML head section.
Version: 1.0
Author: Satya Prakash
Author URI: https://www.satya-weblog.com/
License: Copyright 2010 Satya Prakash (email : [email protected])
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
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, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
* Collect all external js
*/
function orderStyleJS($pos) {
static $ct = 0;
$ct++;
if ($ct == 1) ob_start('outputStyleScriptPlusOtherMeta');
if ($ct > 1 ) ob_end_flush();
}
function jsCodeExternal($strJs) {
preg_match_all('/src\s?=\s?([\'|"])(.*)\1/isU', $strJs, $headerJs2);
$str = '';
foreach ($headerJs2[2] as $val)
{
$str .= '<script src="'.$val.'" type="text/javascript"></script>' . "\n";
}
return $str;
}
/*
* Collect all inline js
*/
function jsCodeInline($strJs) {
$inlineJs = '';
foreach ($strJs as $val)
{
if (! empty($val))
{
$inlineJs .= trim($val) . "\n";
}
}
if ($inlineJs != '') {
$inlineJs = '<script type="text/javascript">' . "\n" .
$inlineJs . "\n" .
'</script>';
}
return $inlineJs;
}
// Grab CSS and JS content and output in order
function outputStyleScriptPlusOtherMeta($headSection) {
// catch external css out for adding later
preg_match_all('@<link+.*(?=(?:type=[\'|"]text/css[\'|"]))(.*?)(?:/>){1,1}@iU', $headSection, $headCSS);
$headSection = preg_replace('@<link+.*(?=(?:type=[\'|"]text/css[\'|"]))(.*?)(?:/>){1,1}@iU', '', $headSection);
// catch Scripts out for adding later
preg_match_all('/<script(.*)>(.*)<\/script>/isU', $headSection, $headJS);
$headSection = preg_replace('@<script(.*)>(.*)<\/script>@isU', '', $headSection);
// remove extra newline
$headSection = preg_replace('@(\r\n|\r|\n){2,}@im' , "\n", $headSection);
$cssCode = '';
foreach ($headCSS[0] as $val)
{
$cssCode .= $val . "\n";
}
$str = $cssCode; // output CSS
// remove closing html tag
$headSection = str_replace('</html>', '', $headSection);
$str .= $headSection; // Output Other data minus css and js
$str .= jsCodeExternal(implode("\n", $headJS[1])); // Output: external Js
$str .= jsCodeInline($headJS[2]); // Output: inline Js
$str .= '<!-- Order style js plugin -->';
// close the html tag
$str .= '<\html>';
return $str;
}
#####################
add_action('admin_menu', 'my_plugin_menu');
function my_plugin_menu() {
add_options_page('Order CSS + Script Options', 'Order CSS + Script', 'manage_options', 'OrderCSSScript', 'my_plugin_options');
}
/**
* Admin Menu HTML
*/
function my_plugin_options() {
if (!current_user_can('manage_options')) {
wp_die( __('You do not have sufficient permissions to access this page.') );
}
echo '<div class="wrap" style="width:90%;margin:20px auto;position:relative">';
echo '<fieldset style="border:2px solid #999;padding:10px">
<legend > <b>Ordering stylesheet and JavaScript:</b> </legend>
';
echo <<<EOD
This does not have any option to use. This is very simple to implement plugin for ordering Styles and Script in <b><head></head></b>
section.
<br />
<b>1</b>. Just add these lines after <b><head></b> or better after <b><head></b> and then <b>Content-Type</b> meta tag:
<pre>
<?php
if (function_exists('orderStyleJS')) {
orderStyleJS( 'start' );
}
?>
</pre>
<b>2</b>. Similar to above, just add these line just before <b></head></b>:
<pre>
<?php
if (function_exists('orderStyleJS')) {
orderStyleJS( 'end' );
}
?>
</pre>
EOD;
echo '
<br /><br />
<div style="clear:both"> </div>
<div style="position:absolute;bottom:10px;left:15px;vertical-align:bottom;border-top:2px dotted #999;width:90%;margin:5px auto;padding:5px">
<a href="https://www.satya-weblog.com/?p=2392" target="_blank">Plugin Discussion</a> |
<a href="https://www.facebook.com/pages/Web-Scripting/176350059435" target="_blank">Facebook</a> |
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=JCVH4RPHL4P5G" target="_blank">Donate</a>
</div>
';
echo '</fieldset></div>';
} // END my_plugin_options
?>
https://www.ads-software.com/plugins/performance-optimization-order-styles-and-javascript/
]]>I followed the instructions I believe to the letter with no positive results.
Help
Thanks,
Dale Morris
https://www.unknowninkdesign.com
https://www.ads-software.com/plugins/performance-optimization-order-styles-and-javascript/
]]>Dear Satya Prakash,
When i tried to activate the plugin, i got the below error.
Fatal error: Cannot redeclare my_plugin_menu() (previously declared in /home/helpinti/public_html/wp-content/plugins/woocommerce-cartconnect/cart_connect.php:167) in /home/helpinti/public_html/wp-content/plugins/performance-optimization-order-styles-and-javascript/order-styles-js.php on line 119
Can you please help us resolve this.
Thanks,
Pavan CH
https://www.ads-software.com/plugins/performance-optimization-order-styles-and-javascript/
]]>After activating and pasted the code properly in the header.php file the left sidebar disappeared and the right sidebar has been moved at the top of the content page and after a while became invisible, main menu has been sent and compressed at the upper right of the page.
How can I fix this problem? Maybe the problem is any incompatibility with the latest wordpress 3.9 update?
Thanks for any help!
Elisa
https://www.ads-software.com/plugins/performance-optimization-order-styles-and-javascript/
]]>I installed an activated this plugin to control the many scripts add from plugins. But I see no difference in the code, nor the results from GT Metrix – is the plugin broken or have I missed something?
Thanks ??
https://www.ads-software.com/plugins/performance-optimization-order-styles-and-javascript/
I forgot to read the install-note – doh!
https://www.ads-software.com/plugins/performance-optimization-order-styles-and-javascript/installation/
…just making sure….
I open header.php and add the additional code there, correct?
Thanks!
https://www.ads-software.com/plugins/performance-optimization-order-styles-and-javascript/
]]>