sumnima sumnima sumnima sumnima sumnima sumnima sumnima
Categories
blog wordpress

Plugin Name: Post/Page Specific JS & CSS

/*
Plugin Name: Post/Page Specific JS & CSS
Description: Add JavaScript and CSS to individual posts/pages
Version: 2.0
*/

Download

<?php
/*
Plugin Name: Post/Page Specific JS & CSS
Description: Add JavaScript and CSS to individual posts/pages
Version: 2.0
License: No License
*/

// Add custom field to post editor
add_action('add_meta_boxes', function() {
	// JavaScript box
	add_meta_box('post_js_box', 'Post JavaScript', 'post_js_meta_box', 'post', 'normal', 'high');
	add_meta_box('post_js_box', 'Page JavaScript', 'post_js_meta_box', 'page', 'normal', 'high');
	
	// CSS box
	add_meta_box('post_css_box', 'Post CSS', 'post_css_meta_box', 'post', 'normal', 'high');
	add_meta_box('post_css_box', 'Page CSS', 'post_css_meta_box', 'page', 'normal', 'high');
});

// JavaScript meta box
function post_js_meta_box($post) {
	wp_nonce_field('post_js_nonce', 'post_js_nonce_field');
	$value = get_post_meta($post->ID, '_post_javascript', true);
	echo '<textarea name="post_javascript" style="width:100%;height:150px;font-family:monospace;" placeholder="// Enter JavaScript code here (without <script> tags)">' . esc_textarea($value) . '</textarea>';
	echo '<p><small>Enter JavaScript without <script> tags. jQuery is available if your theme loads it.</small></p>';
	
	// Show jQuery example
	echo '<details style="margin-top:10px;background:#f5f5f5;padding:10px;">';
	echo '<summary style="cursor:pointer;font-weight:bold;">jQuery Example</summary>';
	echo '<pre style="background:#fff;padding:10px;margin-top:5px;">';
	echo "jQuery(document).ready(function($) {\n";
	echo "    // Your jQuery code here\n";
	echo "    $('.post-title').css('color', 'red');\n";
	echo "});";
	echo '</pre>';
	echo '</details>';
}

// CSS meta box
function post_css_meta_box($post) {
	wp_nonce_field('post_css_nonce', 'post_css_nonce_field');
	$value = get_post_meta($post->ID, '_post_css', true);
	echo '<textarea name="post_css" style="width:100%;height:150px;font-family:monospace;" placeholder="/* Enter CSS code here (without <style> tags) */">' . esc_textarea($value) . '</textarea>';
	echo '<p><small>Enter CSS without <style> tags. Use !important if needed to override theme styles.</small></p>';
	
	// Show CSS examples
	echo '<details style="margin-top:10px;background:#f5f5f5;padding:10px;">';
	echo '<summary style="cursor:pointer;font-weight:bold;">CSS Examples</summary>';
	echo '<pre style="background:#fff;padding:10px;margin-top:5px;">';
	echo "/* Change post title color */\n";
	echo ".entry-title {\n";
	echo "    color: #ff0000 !important;\n";
	echo "}\n\n";
	echo "/* Add border to images in this post */\n";
	echo ".post-" . $post->ID . " img {\n";
	echo "    border: 2px solid #ccc;\n";
	echo "    padding: 5px;\n";
	echo "}\n\n";
	echo "/* Make paragraphs larger */\n";
	echo ".post-" . $post->ID . " p {\n";
	echo "    font-size: 18px;\n";
	echo "    line-height: 1.6;\n";
	echo "}";
	echo '</pre>';
	echo '</details>';
}

// Save custom fields
add_action('save_post', function($post_id) {
	// Save JavaScript
	if (isset($_POST['post_js_nonce_field']) && wp_verify_nonce($_POST['post_js_nonce_field'], 'post_js_nonce')) {
		if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
		if (!current_user_can('edit_post', $post_id)) return;
		
		if (isset($_POST['post_javascript'])) {
			update_post_meta($post_id, '_post_javascript', $_POST['post_javascript']);
		} else {
			delete_post_meta($post_id, '_post_javascript');
		}
	}
	
	// Save CSS
	if (isset($_POST['post_css_nonce_field']) && wp_verify_nonce($_POST['post_css_nonce_field'], 'post_css_nonce')) {
		if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
		if (!current_user_can('edit_post', $post_id)) return;
		
		if (isset($_POST['post_css'])) {
			update_post_meta($post_id, '_post_css', $_POST['post_css']);
		} else {
			delete_post_meta($post_id, '_post_css');
		}
	}
});

// Output JavaScript in footer
add_action('wp_footer', function() {
	if (is_singular()) {
		global $post;
		
		// Output JavaScript
		$js = get_post_meta($post->ID, '_post_javascript', true);
		if (!empty($js)) {
			echo "\n<!-- Post-Specific JavaScript -->\n";
			echo "<script>\n";
			echo "(function() {\n";
			echo "try {\n";
			echo stripslashes(trim($js)) . "\n";
			echo "} catch(e) {\n";
			echo "console.error('Post JS Error on post #" . $post->ID . ":', e);\n";
			echo "}\n";
			echo "})();\n";
			echo "</script>\n";
		}
		
		// Output CSS in footer (as fallback)
		$css = get_post_meta($post->ID, '_post_css', true);
		if (!empty($css)) {
			echo "\n<!-- Post-Specific CSS (in footer) -->\n";
			echo "<style>\n";
			echo stripslashes(trim($css)) . "\n";
			echo "</style>\n";
		}
	}
});

// Output CSS in header (primary location)
add_action('wp_head', function() {
	if (is_singular()) {
		global $post;
		$css = get_post_meta($post->ID, '_post_css', true);
		if (!empty($css)) {
			echo "\n<!-- Post-Specific CSS -->\n";
			echo "<style>\n";
			echo stripslashes(trim($css)) . "\n";
			echo "</style>\n";
		}
	}
});

// Add admin styles for better appearance
add_action('admin_head', function() {
	echo '<style>
	.post-js-box textarea,
	.post-css-box textarea {
		background: #f8f8f8;
		border: 1px solid #ddd;
		border-radius: 4px;
		padding: 10px;
	}
	.post-js-box textarea:focus,
	.post-css-box textarea:focus {
		background: #fff;
		border-color: #007cba;
		box-shadow: 0 0 0 1px #007cba;
	}
	.post-js-box details,
	.post-css-box details {
		border: 1px solid #ddd;
		border-radius: 4px;
	}
	</style>';
});
Categories
bigcommerce blog Child theme cms wordpress wordpress

wordpress remove customize section – child theme

stupid like me want such change 😛

#bookmark #remove #customize #section #wordpress

 

function remove_customize_register() { global $wp_customize; $wp_customize->remove_section( 'colors' ); //Modify this line as needed } add_action( 'customize_register', 'remove_customize_register', 11 );
Categories
blog Storefront WooCommerce wordpress

wordpress woocommerce storefront tab to accordion

tab templates/single-product/tabs

function.php

 

/** * @snippet Move product tabs beside the product image - WooCommerce */ remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 ); add_action( 'woocommerce_single_product_summary', 'woocommerce_output_product_data_tabs', 60 ); add_filter('woocommerce_product_description_heading', '__return_null'); add_filter('woocommerce_product_additional_information_heading', '__return_null');
Categories
blog Storefront WooCommerce wordpress

wordpress Good Good Optimize Stuff


// block WP enum scans 
if (!is_admin()) {
    // default URL format
    if (preg_match('/author=([0-9]*)/i', $_SERVER['QUERY_STRING'])) die();
    add_filter('redirect_canonical', 'shapeSpace_check_enum', 10, 2);
}
function shapeSpace_check_enum($redirect, $request) {
    // permalink URL format
    if (preg_match('/\?author=([0-9]*)(\/*)/i', $request)) die();
    else return $redirect;
}

 
add_action( 'wp_default_scripts', function( $scripts ) {
    if ( ! empty( $scripts->registered['jquery'] ) ) {
        $jquery_dependencies = $scripts->registered['jquery']->deps;
        $scripts->registered['jquery']->deps = array_diff( $jquery_dependencies, array( 'jquery-migrate' ) );
    }
} );
/**
 * Optimize WooCommerce Scripts
 * Remove WooCommerce Generator tag, styles, and scripts from non WooCommerce pages.
 */
add_action( 'wp_enqueue_scripts', 'child_manage_woocommerce_styles', 99 );

 

function cc_mime_types($mimes) {
    $mimes['svg'] = 'image/svg+xml';
    return $mimes;
}
add_filter('upload_mimes', 'cc_mime_types');
  
function woo_registration_redirect() {
    return home_url( '' );
}
 
add_filter( 'registration_redirect', 'woo_registration_redirect' );

remove_action( 'wp_head', 'feed_links_extra', 3 ); // Display the links to the extra feeds such as category feeds
remove_action( 'wp_head', 'feed_links', 2 ); // Display the links to the general feeds: Post and Comment Feed
remove_action( 'wp_head', 'rsd_link' ); // Display the link to the Really Simple Discovery service endpoint, EditURI link
remove_action( 'wp_head', 'wlwmanifest_link' ); // Display the link to the Windows Live Writer manifest file.
remove_action( 'wp_head', 'index_rel_link' ); // index link
remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 ); // prev link
remove_action( 'wp_head', 'start_post_rel_link', 10, 0 ); // start link
remove_action( 'wp_head', 'adjacent_posts_rel_link', 10, 0 ); // Display relational links for the posts adjacent to the current post.
remove_action( 'wp_head', 'wp_generator' ); // Display the XHTML generator that is generated on the wp_head hook, WP version
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'wp_print_styles', 'print_emoji_styles' );

function optimize_jquery() {
    if (!is_admin()) {
        //wp_deregister_script('jquery');
        wp_deregister_script('jquery-migrate.min');
        wp_deregister_script('comment-reply.min');
        $protocol='http:';
        if($_SERVER['HTTPS']=='on') {
            $protocol='https:';
        }
    }
}
add_action('template_redirect', 'optimize_jquery');

// Defer Javascripts
// Defer jQuery Parsing using the HTML5 defer property
if (!(is_admin() )) {
    function defer_parsing_of_js ( $url ) {
        if ( FALSE === strpos( $url, '.js' ) ) return $url;
        if ( strpos( $url, 'jquery.js' ) ) return $url;
        // return "$url' defer ";
        return "$url' defer onload='";
    }
    add_filter( 'clean_url', 'defer_parsing_of_js', 11, 1 );
}


// Disable Heartbeat
add_action( 'init', 'stop_heartbeat', 1 );
function stop_heartbeat() {
wp_deregister_script('heartbeat');
}

 

// Remove WP Version From Styles    
add_filter( 'style_loader_src', 'sdt_remove_ver_css_js', 9999 );
// Remove WP Version From Scripts
add_filter( 'script_loader_src', 'sdt_remove_ver_css_js', 9999 );

// Function to remove version numbers
function sdt_remove_ver_css_js( $src ) {
    if ( strpos( $src, 'ver=' ) )
        $src = remove_query_arg( 'ver', $src );
    return $src;
}

Categories
blog cms multisite Nginx wordpress

wordpress multisite too many server redirects nginx conf

too many server redirects.
 
#wordpress #multisite #wordpressmultisite .conf #nginx #bookmark
 
 
server {
server_name example.com *.example.com ;
 
access_log /var/log/nginx/example.com.access.log;
error_log /var/log/nginx/example.com.error.log;
 
root /var/www/example.com/htdocs;
index index.php;
 
if (!-e $request_filename) {
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
rewrite ^(/[^/]+)?(/wp-.*) $2 last;
rewrite ^(/[^/]+)?(/.*\.php) $2 last;
}
 
location / {
try_files $uri $uri/ /index.php?$args ;
}
 
location ~ \.php$ {
try_files $uri /index.php;
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
 
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
access_log off; log_not_found off; expires max;
}
 
location = /robots.txt { access_log off; log_not_found off; }
location ~ /\. { deny all; access_log off; log_not_found off; }
}
Categories
blog ecommerce WooCommerce wordpress

woocommerce redirect to a custom page after logging out

// redirects for login / logout
add_filter(‘woocommerce_login_redirect’, ‘login_redirect’);

function login_redirect($redirect_to) {

return home_url();
}

add_action(‘wp_logout’,’logout_redirect’);

function logout_redirect(){

wp_redirect( home_url() );

exit();
}

Categories
blog multisite wordpress

wordpress multisite admin login loop

in wp-config file, insert this define line – define(‘COOKIE_DOMAIN’, ‘.yourdomain.com’);