Skip to content

Instantly share code, notes, and snippets.

@ovizii
ovizii / wp-config.php
Last active August 23, 2022 06:59
wp-config.php pimping
//disable auto updating of WP since 3.7
//Disables all core updates:
define( 'WP_AUTO_UPDATE_CORE', false );
//Enables all core updates, including minor and major:
define( 'WP_AUTO_UPDATE_CORE', true );
//Enables core updates for minor releases (default):
define( 'WP_AUTO_UPDATE_CORE', 'minor' );
//only disable updating of the wp.content folder, i.e. no themes and default plugins like akismet and hello dolly
@ovizii
ovizii / functions.php
Last active July 13, 2020 18:17
Remote site snapshot using Wordpress API shortcode
function wpr_snap($atts, $content = null) {
extract(shortcode_atts(array(
"snap" => 'http://s.wordpress.com/mshots/v1/',
"url" => 'http://www.sagive.co.il',
"alt" => 'My image',
"w" => '400', // width
"h" => '300' // height
), $atts));
$img = '<img src="' . $snap . '' . urlencode($url) . '?w=' . $w . '&h=' . $h . '" alt="' . $alt . '"/>';
@ovizii
ovizii / functions.php
Last active January 7, 2018 22:50
Create discreet widget - only shows if not empty
//add discreet text widget
add_action('widgets_init', 'custom_discreet_text_widget');
function custom_discreet_text_widget() {
class DiscreetTextWidget extends WP_Widget_Text {
function DiscreetTextWidget() {
$widget_ops = array('classname' => 'discreet_text_widget', 'description' => __('Arbitrary text or HTML, only shown if not empty'));
$control_ops = array('width' => 400, 'height' => 350);
$this->WP_Widget('discrete_text', __('Discreet Text'), $widget_ops, $control_ops);
}
@ovizii
ovizii / footer.php
Last active January 7, 2018 22:49
Copyright year updated automatically
@ovizii
ovizii / footer.php
Created December 4, 2013 14:28
Display # of queries and exec time
@ovizii
ovizii / functions.php
Created November 15, 2013 11:15
Per post/page custom CSS
//added by Ovi Custom CSS Widget
add_action('admin_menu', 'custom_css_hooks');
add_action('save_post', 'save_custom_css');
add_action('wp_head','insert_custom_css');
//added by Ovi custom CSS Widget, edit below to add to more than posts or pages
function custom_css_hooks() {
add_meta_box('custom_css', 'Custom CSS', 'custom_css_input', 'post', 'normal', 'high');
add_meta_box('custom_css', 'Custom CSS', 'custom_css_input', 'page', 'normal', 'high');
}
@ovizii
ovizii / functions.php
Created August 28, 2013 09:10
Add the “∞” character at the end of the post that links to the post permalink.
//run before wpautop
add_filter( 'the_content', 'my_aside_to_infinity_and_beyond', 9 );
function my_aside_to_infinity_and_beyond( $content ) {
if ( has_post_format( 'aside' ) && !is_singular() )
$content .= ' <a href="' . get_permalink() . '">&#8734;</a>';
return $content;
}
@ovizii
ovizii / functions.php
Created August 23, 2013 07:58
Make atom default feed, remove deprecated ones and redirect them
// set the default feed to atom
add_filter('default_feed','atom_default_feed');
function atom_default_feed() { return 'atom'; }
// remove the rdf and rss 0.92 feeds (nobody ever needs these)
remove_action( 'do_feed_rdf', 'do_feed_rdf', 10, 1 );
remove_action( 'do_feed_rss', 'do_feed_rss', 10, 1 );
// point those feeds at rss 2 (it is backwards compatible with both of them)
add_action( 'do_feed_rdf', 'do_feed_rss2', 10, 1 );
@ovizii
ovizii / functions.php
Created August 20, 2013 17:08
Turn @mentions into unfollowed and _blank Twitter links
/* Automatically link Twitter usernames in WordPress*/
function twtreplace($content) {
return preg_replace('/([^a-zA-Z0-9-_&])@([0-9a-zA-Z_]+)/', "$1<a href=\"http://twitter.com/$2\" target=\"_blank\" rel=\"nofollow\">@$2</a>", $content);
}
add_filter('the_content', 'twtreplace');
add_filter('comment_text', 'twtreplace');
@ovizii
ovizii / 404.php
Created August 20, 2013 09:04
get email alert for 404s
//To implement, simply include this script at the top of your theme’s 404.php file.
//If your theme don’t have a 404.php file, then create it.
<?php // WP 404 ALERTS @ http://wp-mix.com/wordpress-404-email-alerts/
// set status
header("HTTP/1.1 404 Not Found");
header("Status: 404 Not Found");
// site info