11 stories
·
0 followers

CASE NIGHTMARE BOSON: The Summoning Grid Has Been Energized.

jwz
2 Comments
Fake human sacrifice filmed at CERN, with pranking scientists suspected

The European Organisation for Nuclear Research (CERN) has launched an investigation into a video filmed at night on its Geneva campus depicting a mock ritual human sacrifice.

The ceremony appears to have been staged in front of a statue of the Hindu deity Shiva that is on permanent display at the complex, home of the Large Hadron Collider.

"Cern does not condone this type of spoof, which can give rise to misunderstandings about the scientific nature of our work."

Previously, previously, previously, previously, previously, previously, previously.

Read the whole story
dubstep
2798 days ago
reply
they are opening a portal to hell i tell ya
Share this story
Delete
1 public comment
Levitz
2798 days ago
reply
So why is there a Shiva statue at CERN? (if you are going to reply by explaining who Shiva is then you haven't understood my question)

“BUTTS”

1 Comment

This made me laugh “‘BUTTS’ is a profound 3D animated cartoon about anxiety, depression, and lending a hand to those in need. Perhaps the most important film of the decade, ‘BUTTS’ is a reminder that no matter how strange something may seem, people can still make a difference in their own unique and beautiful way.” -some super important idiot. Created by Tyler Hurd

Read the whole story
dubstep
3615 days ago
reply
this is very important
Share this story
Delete

Not drinking will make you sick.

jwz
1 Comment and 3 Shares
Cheers!

The heavy drinkers showed greatly diminished vaccine responses compared with the control group of monkeys who drank the sugar water. But the more surprising finding: the moderate-drinking monkeys displayed enhanced responses to the vaccine compared to the control group. Moderate drinking bolstered their bodies' immune systems.

"It seems that some of the benefits that we know of from moderate drinking might be related in some way to our immune system being boosted by that alcohol consumption," said Kathy Grant, Ph.D., senior author on the paper, a professor of behavioral neuroscience at OHSU and a senior scientist at the ONPRC.

Previously, previously.

Read the whole story
dubstep
3772 days ago
reply
Share this story
Delete
1 public comment
smadin
3773 days ago
reply
Thanks again, Science!
Boston

The Security Risks of Unregulated Google Search

1 Comment and 2 Shares

Someday I need to write an essay on the security risks of secret algorithms that become part of our infrastructure. This paper gives one example of that. Could Google tip an election by manipulating what comes up from search results on the candidates?

The study’s participants, selected to resemble the US voting population, viewed the results for two candidates on a mock search engine called Kadoodle. By front-loading Kadoodle’s results with articles favoring one of the candidates, Epstein shifted enough of his participants' voter preferences toward the favored candidate to simulate the swing of a close election. But here’s the kicker: in one round of the study, Epstein configured Kadoodle so that it hid the manipulation from 100 percent of the participants.

Turns out that it could. And, it wouldn't even be illegal for Google to do it.

The author thinks that government regulation is the only reasonable solution.

Epstein believes that the mere existence of the power to fix election outcomes, wielded or not, is a threat to democracy, and he asserts that search engines should be regulated accordingly. But regulatory analogies for a many-armed, ever-shifting company like Google are tough to pin down. For those who see search results as a mere passive relaying of information, like a library index or a phone book, there is precedent for regulation. In the past, phone books -- with a monopoly on the flow of certain information to the public -- were prevented from not listing businesses even when paid to do so. In the 1990s, similar reasoning led to the "must carry" rule, which required cable companies to carry certain channels to communities where they were the only providers of those channels.

As I said, I need to write an essay on the broader issue.

Read the whole story
dubstep
3971 days ago
reply
Share this story
Delete
1 public comment
Romanikque
3971 days ago
reply
Whoa!
Baltimore, MD

PHP fsockopen for FAST DNS lookups over UDP

1 Share

AskApache.com

While reading up on gethostbyaddr on PHP.net, I saw a nice idea for using fsockopen to connect over UDP port 53 to any Public DNS server, like Google's 8.8.8.8, and sending the reverse addr lookup in oh about 100 bytes, then getting the response in oh about 150 bytes! All in less than a second. This would be extremely valuable for use in things like my online header tool because it's faster than any other method. As usual, I went a bit overboard optimizing it to be lean and fast.

It's also a fairly decent example of how to use fsockopen in general.. Fsockopen enables super-hero-like tricks.

PHP fsockopen for DNS lookups

The function has 3 arguments.

  • An ip address to lookup.
  • A DNS server to query.
  • And a timeout in seconds.

Using the 6 fastest DNS servers

This list includes OpenDNS, UltraDNS, Level3, RoadRunner, and of course, Google DNS (see wikipedia for more).

$ip = '208.86.158.195'; foreach ( array('8.8.8.8', '156.154.70.1', '208.67.222.222', '156.154.70.1', '209.244.0.4', '216.146.35.35') as $dns) { echo gethostbyaddr_timeout( $ip, $dns, 1 ); } 

The gethostbyaddr source

View the syntax highlighted source.

<?php

functiongethostbyaddr_timeout($ip,$dns,$timeout=3) {

// random transaction number (for routers etc to get the reply back)
$data=rand(10,77) ."\1\0\0\1\0\0\0\0\0\0";

// octals in the array, keys are strlen of bit
$bitso= array("","\1","\2","\3");
foreach(
array_reverse(explode('.',$ip) ) as$bit) {
$l=strlen($bit);
$data.="{$bitso[$l]}".$bit;
}

// and the final bit of the request
$data.="\7in-addr\4arpa\0\0\x0C\0\1";

// create UDP socket
$errno=$errstr=0;
$fp=fsockopen("udp://{$dns}",53,$errno,$errstr,$timeout);
if( !
$fp|| !is_resource($fp) )
return
$errno;

if(
function_exists('socket_set_timeout') ) {
socket_set_timeout($fp,$timeout);
} elseif (
function_exists('stream_set_timeout') ) {
stream_set_timeout($fp,$timeout);
}


// send our request (and store request size so we can cheat later)
$requestsize=fwrite($fp,$data);
$max_rx=$requestsize*3;

$start=time();
$responsesize=0;
while (
$received<$max_rx&& ( (time() -$start) <$timeout) && ($buf=fread($fp,1) ) !==false) {
$responsesize++;
$response.=$buf;
}
//echo

echo
"[tx:$requestsizebytes] [rx:{$responsesize}bytes]";

// hope we get a reply
if (is_resource($fp) )
fclose($fp);

// if empty response or bad response, return original ip
if ( empty($response) ||bin2hex(substr($response,$requestsize+2,2) ) !='000c')
return
$ip;

// set up our variables
$host='';
$len=$loops=0;

// set our pointer at the beginning of the hostname uses the request size from earlier rather than work it out
$pos=$requestsize+12;
do {
// get segment size
$len=unpack('c',substr($response,$pos,1) );

// null terminated string, so length 0 = finished - return the hostname, without the trailing .
if ($len[1] ==0)
return
substr($host,0, -1);

// add segment to our host
$host.=substr($response,$pos+1,$len[1] ) .'.';

// move pointer on to the next segment
$pos+=$len[1] +1;

// recursion protection
$loops++;
}
while (
$len[1] !=0&&$loops<20);

// return the ip in case
return$ip;
}


?>

Download and Copy Code

Or download from: gethostbyaddr.txt

function gethostbyaddr_timeout( $ip, $dns, $timeout = 3 ) { // idea from http://www.php.net/manual/en/function.gethostbyaddr.php#46869 // http://www.askapache.com/pub/php/gethostbyaddr.php // random transaction number (for routers etc to get the reply back) $data = rand( 10, 77 ) . "\1\0\0\1\0\0\0\0\0\0"; // octals in the array, keys are strlen of bit $bitso = array("","\1","\2","\3" ); foreach( array_reverse( explode( '.', $ip ) ) as $bit ) { $l=strlen($bit); $data.="{$bitso[$l]}".$bit; } // and the final bit of the request $data .= "\7in-addr\4arpa\0\0\x0C\0\1"; // create UDP socket $errno = $errstr = 0; $fp = fsockopen( "udp://{$dns}", 53, $errno, $errstr, $timeout ); if( ! $fp || ! is_resource( $fp ) ) return $errno; if( function_exists( 'socket_set_timeout' ) ) { socket_set_timeout( $fp, $timeout ); } elseif ( function_exists( 'stream_set_timeout' ) ) { stream_set_timeout( $fp, $timeout ); } // send our request (and store request size so we can cheat later) $requestsize = fwrite( $fp, $data ); $max_rx = $requestsize * 3; $start = time(); $responsesize = 0; while ( $received < $max_rx && ( ( time() - $start ) < $timeout ) && ($buf = fread( $fp, 1 ) ) !== false ) { $responsesize++; $response .= $buf; } // echo "[tx: $requestsize bytes] [rx: {$responsesize} bytes]"; // hope we get a reply if ( is_resource( $fp ) ) fclose( $fp ); // if empty response or bad response, return original ip if ( empty( $response ) || bin2hex( substr( $response, $requestsize + 2, 2 ) ) != '000c' ) return $ip; // set up our variables $host = ''; $len = $loops = 0; // set our pointer at the beginning of the hostname uses the request size from earlier rather than work it out $pos = $requestsize + 12; do { // get segment size $len = unpack( 'c', substr( $response, $pos, 1 ) ); // null terminated string, so length 0 = finished - return the hostname, without the trailing . if ( $len[1] == 0 ) return substr( $host, 0, -1 ); // add segment to our host $host .= substr( $response, $pos + 1, $len[1] ) . '.'; // move pointer on to the next segment $pos += $len[1] + 1; // recursion protection $loops++; } while ( $len[1] != 0 && $loops < 20 ); // return the ip in case return $ip; } 

PHP fsockopen for FAST DNS lookups over UDP… originally appeared on AskApache.com

The post PHP fsockopen for FAST DNS lookups over UDP appeared first on AskApache.

Read the whole story
dubstep
4007 days ago
reply
Share this story
Delete

WordPress Snippets That Solve Annoying Problems – 27 Examples

1 Share

WordPress can be customized easily and that is the beauty of it, that you can adapt it to whatever purpose you would want your site to have. If you don’t like something about it you will always have the option to change it. The easiest way to do that is by using a plugin, but if you would be using a plugin for every little thing that you need you would end up with a lot of plugins and that is never recommended.

Try to use plugins just for the complicated actions that you can’t customize yourself. If there some small modification that you want to make to the theme, just do it yourself in the code, don’t use a plugin for it, instead use a snippet. WordPress snippets are some of the best things that you can find online related to WordPress customization. There’s a little modification that can be made for almost every customization that you can think of.

In this article you will see WordPress code snippets for a few interesting problems, not the regular ones that you see almost everywhere posted. I hope these will help you as much as they helped me.

These all go into the functions.php file. I know it might look silly to some of you that I mentioned this, but there are also WordPress beginners and might not know it.

Pagination for Twitter Bootstrap

<?php

// Numeric Page Navi
function page_navi($before = '', $after = '') {
	global $wpdb, $wp_query;
	$request = $wp_query->request;
	$posts_per_page = intval(get_query_var('posts_per_page'));
	$paged = intval(get_query_var('paged'));
	$numposts = $wp_query->found_posts;
	$max_page = $wp_query->max_num_pages;
	if ( $numposts <= $posts_per_page ) { return; }
	if(empty($paged) || $paged == 0) {
		$paged = 1;
	}
	$pages_to_show = 7;
	$pages_to_show_minus_1 = $pages_to_show-1;
	$half_page_start = floor($pages_to_show_minus_1/2);
	$half_page_end = ceil($pages_to_show_minus_1/2);
	$start_page = $paged - $half_page_start;
	if($start_page <= 0) {
		$start_page = 1;
	}
	$end_page = $paged + $half_page_end;
	if(($end_page - $start_page) != $pages_to_show_minus_1) {
		$end_page = $start_page + $pages_to_show_minus_1;
	}
	if($end_page > $max_page) {
		$start_page = $max_page - $pages_to_show_minus_1;
		$end_page = $max_page;
	}
	if($start_page <= 0) {
		$start_page = 1;
	}
		
	echo $before.'<div class="pagination"><ul class="clearfix">'."";
	if ($paged > 1) {
		$first_page_text = "«";
		echo '<li class="prev"><a href="'.get_pagenum_link().'" title="First">'.$first_page_text.'</a></li>';
	}
		
	$prevposts = get_previous_posts_link('← Previous');
	if($prevposts) { echo '<li>' . $prevposts  . '</li>'; }
	else { echo '<li class="disabled"><a href="#">← Previous</a></li>'; }
	
	for($i = $start_page; $i  <= $end_page; $i++) {
		if($i == $paged) {
			echo '<li class="active"><a href="#">'.$i.'</a></li>';
		} else {
			echo '<li><a href="'.get_pagenum_link($i).'">'.$i.'</a></li>';
		}
	}
	echo '<li class="">';
	next_posts_link('Next →');
	echo '</li>';
	if ($end_page < $max_page) {
		$last_page_text = "»";
		echo '<li class="next"><a href="'.get_pagenum_link($max_page).'" title="Last">'.$last_page_text.'</a></li>';
	}
	echo '</ul></div>'.$after."";
}

?>

Insert this snippet in your functions.php. It creates a numbered page navigation menu using Twitter Boostrap native CSS classes. Use in your template files by calling the function

page_navi();

Github Gist shortcode

This code snippet will detect links to Github Gist in posts and replace them with shortcodes and then shortcodes will be replaced with embedded gist. Just add the code to your functions.php

<?php
// [gist id="ID" file="FILE"]
function gist_shortcode($atts) {
  return sprintf(
    '<script src="https://gist.github.com/%s.js%s"></script>', 
    $atts['id'], 
    $atts['file'] ? '?file=' . $atts['file'] : ''
  );
} add_shortcode('gist','gist_shortcode');

// Remove this function if you don't want autoreplace gist links to shortcodes
function gist_shortcode_filter($content) {
  return preg_replace('/https:\/\/gist.github.com\/([\d]+)[\.js\?]*[\#]*file[=|_]+([\w\.]+)(?![^<]*<\/a>)/i', '[gist id="${1}" file="${2}"]', $content );
} add_filter( 'the_content', 'gist_shortcode_filter', 9);
?>

Formats:

https://gist.github.com/1147076

https://gist.github.com/1147076#file_annotated.js

https://gist.github.com/1147076.js?file=annotated.js

[gist id=1147076]
[gist id=1147076 file=annotated.js]

This works perfectly in most cases but there is one(or more?) case when it doesn’t work as it should:

https://gist.github.com/1147076#file_license.txt

If we add this url to our post it will display all files from this gist. It’s because file name in gist is uppercased. But this one will work corectly:

https://gist.github.com/1147076.js?file=LICENSE.txt

Automatically set the featured image

If you set a featured image, then that will be the featured image, otherwise, the first one of the article will be set as featured image.

<?php
function autoset_featured() {
          global $post;
          $already_has_thumb = has_post_thumbnail($post->ID);
              if (!$already_has_thumb)  {
              $attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );
                          if ($attached_image) {
                                foreach ($attached_image as $attachment_id => $attachment) {
                                set_post_thumbnail($post->ID, $attachment_id);
                                }
                           }
                        }
      }  //end function
add_action('the_post', 'autoset_featured');
add_action('save_post', 'autoset_featured');
add_action('draft_to_publish', 'autoset_featured');
add_action('new_to_publish', 'autoset_featured');
add_action('pending_to_publish', 'autoset_featured');
add_action('future_to_publish', 'autoset_featured');
?>

Source

Breadcrumbs without plugin

<?php
function the_breadcrumb() {
		echo '<ul id="crumbs">';
	if (!is_home()) {
		echo '<li><a href="';
		echo get_option('home');
		echo '">';
		echo 'Home';
		echo "</a></li>";
		if (is_category() || is_single()) {
			echo '<li>';
			the_category(' </li><li> ');
			if (is_single()) {
				echo "</li><li>";
				the_title();
				echo '</li>';
			}
		} elseif (is_page()) {
			echo '<li>';
			echo the_title();
			echo '</li>';
		}
	}
	elseif (is_tag()) {single_tag_title();}
	elseif (is_day()) {echo"<li>Archive for "; the_time('F jS, Y'); echo'</li>';}
	elseif (is_month()) {echo"<li>Archive for "; the_time('F, Y'); echo'</li>';}
	elseif (is_year()) {echo"<li>Archive for "; the_time('Y'); echo'</li>';}
	elseif (is_author()) {echo"<li>Author Archive"; echo'</li>';}
	elseif (isset($_GET['paged']) && !empty($_GET['paged'])) {echo "<li>Blog Archives"; echo'</li>';}
	elseif (is_search()) {echo"<li>Search Results"; echo'</li>';}
	echo '</ul>';
}
?>

And for the function to be called, use the following code in the page that you want.

<?php the_breadcrumb(); ?>

Keep WordPress from compressing JPGs

<?php
add_filter('jpeg_quality', function($arg){return 100;});
?>

Source

Extend search to include custom post meta

<?php

/*
 * Extend wp search to include custom post meta 
 */

function custom_search_query( $query ) {
	if ( !is_admin() && $query->is_search ) {
		$query->set('meta_query', array(
			array(
				'key' => '__meta_key__',
				'value' => $query->query_vars['s'],
				'compare' => 'LIKE'
			)
		));
         $query->set('post_type', '__your_post_type__'); // optional
	};
}
add_filter( 'pre_get_posts', 'dc_custom_search_query');
?>

Add links to WordPress 3.3 New Toolbar

<?php

add_action('admin_bar_menu', 'add_toolbar_items', 100);
function add_toolbar_items($admin_bar){
	$admin_bar->add_menu( array(
		'id'    => 'my-item',
		'title' => 'My Item',
		'href'  => '#',
		'meta'  => array(
			'title' => __('My Item'),			
		),
	));
	$admin_bar->add_menu( array(
		'id'    => 'my-sub-item',
		'parent' => 'my-item',
		'title' => 'My Sub Menu Item',
		'href'  => '#',
		'meta'  => array(
			'title' => __('My Sub Menu Item'),
			'target' => '_blank',
			'class' => 'my_menu_item_class'
		),
	));
	$admin_bar->add_menu( array(
		'id'    => 'my-second-sub-item',
		'parent' => 'my-item',
		'title' => 'My Second Sub Menu Item',
		'href'  => '#',
		'meta'  => array(
			'title' => __('My Second Sub Menu Item'),
			'target' => '_blank',
			'class' => 'my_menu_item_class'
		),
	));
}

?>

Add custom image sizes to media insert dialog

<?php

if ( function_exists( 'add_image_size' ) ) {
    add_image_size( 'new-size', 300, 100, true ); //(cropped)
}
 
add_filter('image_size_names_choose', 'my_image_sizes');
function my_image_sizes($sizes) {
        $addsizes = array(
                "new-size" => __( "New Size")
                );
        $newsizes = array_merge($sizes, $addsizes);
        return $newsizes;
}

?>

Source

Different admin and theme languages

Don’t define WPLANG in wp-config. That’s really silly. Try this instead.

<?php
// setup one language for admin and the other for theme
// must be called before load_theme_textdomain()
function set_my_locale($locale) {
	
	$locale = ( is_admin() ) ? "en_US" : "it_IT";
	setlocale(LC_ALL, $local );
	return $locale;

}
add_filter( 'locale', 'set_my_locale' );
?>

Change default from address

<?php
add_filter('wp_mail_from', 'new_mail_from');
add_filter('wp_mail_from_name', 'new_mail_from_name');

function new_mail_from($old) {
 return 'no-reply@example.com';
}

function new_mail_from_name($old) {
 return 'Dave Thomas';
}
?>

Truncate post title

<?php
function customTitle($limit) {
    $title = get_the_title($post->ID);
    if(strlen($title) > $limit) {
        $title = substr($title, 0, $limit) . '...';
    }
    
    echo $title;
}
?>

When you’re in need of truncating a title, call:

customTitle(50)

Where (50) is the number of Characters it allows before truncating.

Simple HTML in widget title

The snippet makes it possible to use (type [s] and [/s] in widget title) and (type [e] and [/e] in widget title) tags only but other HTML tags can be added easily if you want to.

<?php
function html_widget_title( $title ) {
	//HTML tag opening/closing brackets
	$title = str_replace( '[', '<', $title );
	$title = str_replace( '[/', '</', $title );

	//<strong></strong>
	$title = str_replace( 's]', 'strong>', $title );
	//<em></em>
	$title = str_replace( 'e]', 'em>', $title );

	return $title;
}
add_filter( 'widget_title', 'html_widget_title' );
?>

Post views without plugin

<?php
// function to display number of posts.
function getPostViews($postID){
    $count_key = 'post_views_count';
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
        return "0 View";
    }
    return $count.' Views';
}

// function to count views.
function setPostViews($postID) {
    $count_key = 'post_views_count';
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        $count = 0;
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
    }else{
        $count++;
        update_post_meta($postID, $count_key, $count);
    }
}


// Add it to a column in WP-Admin
add_filter('manage_posts_columns', 'posts_column_views');
add_action('manage_posts_custom_column', 'posts_custom_column_views',5,2);
function posts_column_views($defaults){
    $defaults['post_views'] = __('Views');
    return $defaults;
}
function posts_custom_column_views($column_name, $id){
	if($column_name === 'post_views'){
        echo getPostViews(get_the_ID());
    }
}
?>

After that add this to single.php

<?php setPostViews(get_the_ID()); ?>

And to display the number of views a post has, add this where you want it to be displayed:

<?php echo getPostViews(get_the_ID()); ?>

Source

Exclude category from homepage

<?php
function excludeCat($query) {
  if ( $query->is_home ) {
    $query->set('cat', '-3,-5,-23');
  }
  return $query;
}
add_filter('pre_get_posts', 'excludeCat');
?>

Load jQuery in footer

<?php
/**
 * Prints jQuery in footer on front-end.
 */
function ds_print_jquery_in_footer( &$scripts) {
	if ( ! is_admin() )
		$scripts->add_data( 'jquery', 'group', 1 );
}
add_action( 'wp_default_scripts', 'ds_print_jquery_in_footer' );

?>

Source

Include future posts in RSS feed

Correct scheduled posts do not appear in the rss feed. With this function it will include your scheduled posts in the rss feed. However, it will not be found if clicked.

<?php
/* Include published and future posts in rss feed. */
function FuturePostsFeed($query) {
    if ($query->is_feed) {
         $query->set('post_status','publish,future');
    }
return $query;
}
add_filter('pre_get_posts','FuturePostsFeed');
?>

Restrict user access

With this snippet you can create a page template restricted only to those users with the right role to access to it.

<?php
/* Template Name: Restricted to Authors only */
if ( !current_user_can('author')) {
	include('error.php');
	exit(0);
}
?>

.htaccess Gzip compression

Compression reduces response times by reducing the size of the HTTP response. Gzip is the most popular and effective compression method currently available and generally reduces the response size by about 70%. Approximately 90% of today’s Internet traffic travels through browsers that claim to support gzip.

You’ll have to add this code to the .htaccess file:

<IfModule mod_gzip.c>
    mod_gzip_on       Yes
    mod_gzip_dechunk  Yes
    mod_gzip_item_include file      \.(html?|txt|css|js|php|pl)$
    mod_gzip_item_include handler   ^cgi-script$
    mod_gzip_item_include mime      ^text/.*
    mod_gzip_item_include mime      ^application/x-javascript.*
    mod_gzip_item_exclude mime      ^image/.*
    mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>

or

# BEGIN GZIP
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</ifmodule>
# END GZIP

Source

Schedule cron jobs with WordPress

<?php
add_action('my_hourly_event', 'do_this_hourly');

function my_activation() {
	if ( !wp_next_scheduled( 'my_hourly_event' ) ) {
		wp_schedule_event(time(), 'hourly', 'my_hourly_event');
	}
}
add_action('wp', 'my_activation');

function do_this_hourly() {
	// do something every hour
}
?>

More info in cron jobs here

Custom admin CSS

You can change the default style of WordPress admin area by overriding the old stylesheet. To do this, you have to create a new css file in your theme folder, and then include it in WP-Admin using the admin_head hook.

<?php
function customAdmin() {
    $url = get_settings('siteurl');
    $url = $url . '/wp-content/themes/my-theme/styles/wp-admin.css';
    echo '&lt;!-- custom admin css -->
          &lt;link rel="stylesheet" type="text/css" href="' . $url . '" />
          &lt;!-- /end custom adming css -->';
}
add_action('admin_head', 'customAdmin');
?>

Enable threaded comments

WordPress has support for threaded comments, but you have to enable it yourself by adding a script to your head. You can use WordPress built in function wp_enqueue_script () to load the script, by adding this snippet to your functions.php.

When the script is loaded, you have to activate the threaded comments in the settings tab in WordPress admin, under Settings > Discussion. Click Enable threaded (nested) comments and choose the level of nested comments you want.

<?php
function enable_threaded_comments(){
    if (is_singular() AND comments_open() AND (get_option('thread_comments') == 1)) {
       wp_enqueue_script('comment-reply');
    }
}
add_action('get_header', 'enable_threaded_comments');
?>

Remove update notification for regular users

This hides the update message that is displayed when there is a new version of WordPress available.

<?php
if ( !current_user_can('administrator') ) {
    add_action( 'init', create_function( '$a', "remove_action( 'init', 'wp_version_check' );" ), 2 );
    add_filter( 'pre_option_update_core', create_function( '$a', "return null;" ) );
}
?>

Limit amount of post revisions

Why? Because post revisions can inflate your database at an annoying pace so you have to stop this. Paste this code in wp-config

# Maximum 5 revisions #
define('WP_POST_REVISIONS', 5);
# Disable revisions #
define('WP_POST_REVISIONS', false);

Code in posts without a plugin

To use this little hack, simply put the code between [ code ] and [ /code ] (without spaces).

<?php
function bbcode( $attr, $content = null ) {
        $content = clean_pre($content); // Clean pre-tags
        return '<pre"><code>' .
                str_replace('<', '<', $content) . // Escape < chars
                '</code></pre>';
    }
add_shortcode('code', 'bbcode');
?>

Disable Google Analytics for logged in users

This snippet automatically adds the Google Analytics code to your footer area (in case wp_footer () is called), so you don’t have to manually insert the Analytics code to all your files.

<?php
// function for inserting Google Analytics into the wp_head
add_action('wp_footer', 'ga');
function ga() {
   if ( !is_user_logged_in() ) { // not for logged in users
?>
<script type="text/javascript">
	  var _gaq = _gaq || [];
	  _gaq.push(['_setAccount', 'UA-XXXXXXXX']); // insert your Google Analytics id here
	  _gaq.push(['_trackPageview']);
	  _gaq.push(['_trackPageLoadTime']);
	  (function() {
	    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
	  })();
	</script>
<?php
   }
}
?>

Custom feed footer without a plugin

<?php
if ( !function_exists('custom_feed_footer') )
{
	function custom_feed_footer($content)
	{
		if(is_feed())
		$content .= 'Your text';
		return $content;
	}
	add_filter('the_excerpt_rss', 'custom_feed_footer');
	add_filter('the_content', 'custom_feed_footer');
}
?>
Read the whole story
dubstep
4023 days ago
reply
Share this story
Delete
Next Page of Stories