strykerraven
strykerraven
Reputation Top 1%
Jason
Web Developer (PHP7,HTML5,CSS3,jQuery)
2 Snippets  (264th place)
Published
2 Channels
Created
3 Channels
Following
1988 points  (34th place)
Reputation
Junior Code Generator
Junior Publisher
Junior Topic Creator
Junior Topic Hub
Junior Trend Maker
Junior Judge
Junior Autobiographer
Serious Autobiographer
Junior Snip2Coder
Junior Famous Coder
Junior Wise Coder

Recent Snippets See all snippets by strykerraven

public by strykerraven  188263  7  5  1

WordPress safely defining and executing functions

Handy safe way to include functions in your WordPress Themes functions.php file. This is even more useful if you are using a child theme and don't want to conflict with functions already defined by the parent theme. Even better; These functions can be executed within the same if(function_exists()) block that defines them creating a neater to manage
<?php

// Lets get rid of the versioning on static .js and .css files.
// It looks tacky anyway for static files.

	/**
	 * Strips Version query strings
	 * @param type $src
	 * @return type
	 */
	if(!function_exists('remove_css_js_versions')){ // if the function doesnt exist then...
		function remove_css_js_versions($src){ // define the function
			return remove_query_arg('ver', $src); // call built-in wordpress function to remove query named "ver" from whatever is passed as $src
		}
		add_filter('script_loader_src', 'remove_css_js_versions'); // Pass a hook as $src for js to function listed above named "remove_css_js_versions"
		add_filter('style_loader_src', 'remove_css_js_versions'); // Pass a hook as $src for css to function listed above named "remove_css_js_versions"
	} // All scripts and styles will be filtered to have ?ver=1.2.3 stripped from urls. Function defined and executed in same if() statement.

  /**
  * Need to debug? Instead of just using print_r($array) you just do preprint_r($array)
  * the array will be output neatly instead of wrapped and messy.
  */
	if(!function_exists('preprint_r')){
		function preprint_r($val){
			echo '<pre>' . PHP_EOL;
			print_r($val) . PHP_EOL;
			echo '</pre>' . PHP_EOL;
		}
	}
	
	/** Remove the WP Icon (Menu) from profile and admin pages. */
		if(!function_exists('remove_wp_logo')){
  		function remove_wp_logo($wp_admin_bar){
  			$wp_admin_bar->remove_node('wp-logo');
  		}
  		add_action('admin_bar_menu', 'remove_wp_logo', 33);
  	}
  	
/**
	 * Wordpress Login Page fixes. By default WordPress shows its logo on your login pages and links to its own site.
	 * A visitor logging into your site don't need this potential roadblock so lets show WordPress that we mean business!
	 */
	# Fix Login Page WordPress URL
	if(!function_exists('fix_wp_login_img_url')){
		function fix_wp_login_img_url($url){
			return get_bloginfo('url');
		}
		add_filter('login_headerurl', 'fix_wp_login_img_url');
	}

	# Fix Login Page WordPress Title (Text displayed on hover defaults to Powered By WordPress)
	if(!function_exists('fix_wp_login_img_title')){
		function fix_wp_login_img_title($title){
			return get_bloginfo('description');
		}
		add_filter('login_headertitle', 'fix_wp_login_img_title');
	}

	/**
		Change Login Page WordPress Logo, You will need to update path and point to a valid image.
		WordPress adds this with a CSS background image for your anchor link. It first applys a PNG and then a SVG override if your browser is modern and supports svg
		In your themes custom stylesheet you can change default Wordpress image by supplying a new background image:

		.login h1 a {
			background-image: none,url(images/your_image.png);
		}

		Hint: WordPress uses an 64x64 image but you can adapt size to your need. You might want to use SVG like WordPress did because it will scale best at any resolution.

	 */

	/**
	 * Simple Actions that use wp_head hook to cleanup WP header Junk/Bloat
	 * that is included with WordPress by default.
	 */
	remove_action('wp_head', 'wp_generator');
	remove_action('wp_head', 'rsd_link');
	remove_action('wp_head', 'wlwmanifest_link');
	remove_action('wp_head', 'wp_shortlink_wp_head');            
	
	
	?>
;

public by strykerraven  4616  3  6  1

Limit and/or Disable Wordpress Revisions

The revisions fill up your mysql database over time... Here's how to fix. ADDED: More Tweaks
<?

// Add this to end of wp-config.php right above the following line:
/** Absolute path to the WordPress directory. */

define( 'WP_POST_REVISIONS', 3 ); // Limits to 3 revisions + Original
// OR
define( 'WP_POST_REVISIONS', FALSE ); // fully disables revisions  


// No need for a plugin (ya they exist but this is easy enough and no bloat)

// Some other easy tweaks:
define('EMPTY_TRASH_DAYS', 7); // Auto Empty the Trash every 7 days (default 30)
define('AUTOSAVE_INTERVAL', 120); // Auto-Saves post every 120 Seconds (default is 60)
define('WP_MEMORY_LIMIT', '160M'); // Used on front-end
define('WP_MAX_MEMORY_LIMIT', '256M'); // Used on backend (Admin Pages etc)            

?>
;