IMPORTANT!

Snipt is going open source. We've toyed with this idea for quite a while, and have finally decided it's the right way to move forward.

A few things:
  • The entire Snipt source code will be released on GitHub under the 3-clause BSD License on Friday, September 10th.
  • While we'd like to think we're perfect, we realize we're only human. By open sourcing the software that runs this website, certain bugs or security flaws may be discovered that could compromise the privacy of your snipts.
  • Only the Lion Burger team will be able to push commits to the Snipt.net site. Contributors should send a pull request to add new features or submit patches.
  • By using this site, you agree not to be too angry or take any legal action against Lion Burger should this whole thing go up in flames some day.
  • Follow us on Twitter for updates.
I agree, close this message
Sign up to create your own snipts, or login.

Latest 100 public snipts » wordpress The latest public wordpress snipts.

showing 1-20 of 161 snipts for wordpress
  • Get Template Directory
    <?php bloginfo( 'template_directory' ); ?>
    

    copy | embed

    0 comments - tagged in  posted by skotmxpx on Sep 01, 2010 at 4:46 p.m. EDT
  • Blog home and site address
    define('WP_HOME', 'http://digwp.com'); // no trailing slash
    define('WP_SITEURL', 'http://digwp.com');  // no trailing slash
    

    copy | embed

    0 comments - tagged in  posted by skotmxpx on Aug 31, 2010 at 4:43 p.m. EDT
  • Shotcode: Show Related Posts (based on tags)
    <?php
    function related_posts_shortcode( $atts ) {
    	extract(shortcode_atts(array(
    		'limit' => '5',
    	), $atts));
    
    	global $wpdb, $post, $table_prefix;
    
    	if ($post->ID) {
    		$retval = '<ul>';
     		// Get tags
    		$tags = wp_get_post_tags($post->ID);
    		$tagsarray = array();
    		foreach ($tags as $tag) {
    			$tagsarray[] = $tag->term_id;
    		}
    		$tagslist = implode(',', $tagsarray);
    
    		// Do the query
    		$q = "SELECT p.*, count(tr.object_id) as count
    			FROM $wpdb->term_taxonomy AS tt, $wpdb->term_relationships AS tr, $wpdb->posts AS p WHERE tt.taxonomy ='post_tag' AND tt.term_taxonomy_id = tr.term_taxonomy_id AND tr.object_id  = p.ID AND tt.term_id IN ($tagslist) AND p.ID != $post->ID
    				AND p.post_status = 'publish'
    				AND p.post_date_gmt < NOW()
     			GROUP BY tr.object_id
    			ORDER BY count DESC, p.post_date_gmt DESC
    			LIMIT $limit;";
    
    		$related = $wpdb->get_results($q);
     		if ( $related ) {
    			foreach($related as $r) {
    				$retval .= '
    	<li><a title="'.wptexturize($r->post_title).'" href="'.get_permalink($r->ID).'">'.wptexturize($r->post_title).'</a></li>
    ';
    			}
    		} else {
    			$retval .= '
    	<li>No related posts found</li>
    ';
    		}
    		$retval .= '</ul>
    ';
    		return $retval;
    	}
    	return;
    }
    add_shortcode('related_posts', 'related_posts_shortcode');
    
    /* 
     * Usage:
     * [related_posts]
     * [related_posts limit="x"] to show a number of your choosing
     * Credit goes to Blue Anvil (http://blue-anvil.com/archives/8-fun-useful-shortcode-functions-for-wordpress/).
     */
    ?>
    

    copy | embed

    0 comments - tagged in  posted by oriol_tf on Aug 31, 2010 at 6:15 a.m. EDT
  • wordpress get posts
    <?php
    
    function getPosts($path, $number)
    {
    	$posts = array();
    	$buffer = file_get_contents($path);
    	
    	// Create a new SimpleXML string
    	$xml = new SimpleXMLElement($buffer);
    	
    	// extract the information we want
    	$channel = $xml -> channel;
    	
    	$count = $number;
    	$i = 1;
    	foreach ($channel->item as $post) {
    		if ($i > $count) break;
        	$posts = array(	'title' => $post->title,
    						'link' => $post->link
    						);
    		$i++;
    	}
    	return $posts;
    
    }
    

    copy | embed

    0 comments - tagged in  posted by jameswmcnab on Aug 28, 2010 at 2:53 p.m. EDT
  • Functions.php Framework
    <?php
    
    // --------------  Add support for nav menus -------------- 
    add_theme_support( 'nav-menus' );
    
    register_nav_menus( array(
    		'header' => __( 'Header Menu'),
    ) );
    
    // --------------  Add support for gallery post thumbnails -------------- 
    add_theme_support( 'post-thumbnails');
    set_post_thumbnail_size( 310, 650); 
    add_image_size( 'col1', 135, 650);
    
    // smart jquery inclusion
    if (!is_admin()) {
    	wp_deregister_script('jquery');
    	wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"), false);
    	wp_enqueue_script('jquery');
    }
    
    // enable threaded comments
    function enable_threaded_comments(){
    	if (!is_admin()) {
    		if (is_singular() AND comments_open() AND (get_option('thread_comments') == 1))
    			wp_enqueue_script('comment-reply');
    		}
    }
    add_action('get_header', 'enable_threaded_comments');
    
    // no more jumping for read more link
    function no_more_jumping($post) {
    	return '<a href="'.get_permalink($post->ID).'" class="read-more">'.'Continue Reading'.'</a>';
    }
    add_filter('excerpt_more', 'no_more_jumping');
    
    
    
    ?>
    

    copy | embed

    0 comments - tagged in  posted by sawyer on Aug 24, 2010 at 12:34 p.m. EDT
  • Redirect to first child page
    <?php
    
    /*
    Template Name: Parent 
    */
    
    if (have_posts()) {
      while (have_posts()) {
        the_post();
        $pagekids = get_pages("child_of=".$post->ID."&sort_column=menu_order");
        $firstchild = $pagekids[0];
        wp_redirect(get_permalink($firstchild->ID));
      }
    }
    ?>
    

    copy | embed

    0 comments - tagged in  posted by martinkacmar on Aug 23, 2010 at 3:25 p.m. EDT
  • Getting rid of the 'allowed tags' in Wordpress comment forms.
    <?php comment_form(array('comment_notes_after' => '')); ?>
    

    copy | embed

    0 comments - tagged in  posted by d13t on Aug 16, 2010 at 6:05 a.m. EDT
  • Modify the_excerpt() output
    <?php
    function my_excerpt_length($text){
    	return 10;
    }
    add_filter('excerpt_length', 'my_excerpt_length');
    
    function new_excerpt_more($more) {
    	return '...';
    }
    add_filter('excerpt_more', 'new_excerpt_more');
    ?>
    

    copy | embed

    0 comments - tagged in  posted by depi on Aug 14, 2010 at 12:57 p.m. EDT
  • wordpress display custom value
    <?php $values = get_post_custom_values('image'); echo $values[0]; ?>
    

    copy | embed

    0 comments - tagged in  posted by aike on Aug 12, 2010 at 12:19 p.m. EDT
  • Get unique salts for a WP installation
    curl https://api.wordpress.org/secret-key/1.1/salt/ > salt.txt
    

    copy | embed

    0 comments - tagged in  posted by shacker on Aug 10, 2010 at 2:17 p.m. EDT
  • Return post_thumbnail URL
    <?php
    $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(), 'medium');
    
    // Returns the URL for the "Medium" post thumbnail
    echo $thumbnail[0];
    ?>
    

    copy | embed

    0 comments - tagged in  posted by sawyer on Aug 09, 2010 at 4:03 p.m. EDT
  • worrdpress loop
    /*THE LOOP - START*/
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    /*THE LOOP - END*/
    <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>
    

    copy | embed

    0 comments - tagged in  posted by aike on Aug 06, 2010 at 4:08 a.m. EDT
  • removes heading in list pages
    <ul>
    <?php wp_list_pages('title_li='); ?>
    </ul>
    

    copy | embed

    0 comments - tagged in  posted by aike on Aug 05, 2010 at 6:40 a.m. EDT
  • adds first-page-item class to first item in list-pages
    <?php
    function add_markup_pages($output) {
        $output= preg_replace('/page-item/', ' first-page-item page-item', $output, 1);
    	$output=substr_replace($output, " last-page-item page-item", strripos($output, "page-item"), strlen("page-item"));
        return $output;
    }
    add_filter('wp_list_pages', 'add_markup_pages');
    
    ?>
    

    copy | embed

    0 comments - tagged in  posted by aike on Aug 05, 2010 at 6:38 a.m. EDT
  • Get WordPress page slug
    // Add to functions.php
    
    function the_slug() {
    $post_data = get_post($post->ID, ARRAY_A);
    $slug = $post_data['post_name'];
    return $slug; }
    
    // Add within the Loop
    
    <?php echo the_slug(); ?>
    

    copy | embed

    0 comments - tagged in  posted by sawyer on Aug 04, 2010 at 11:25 a.m. EDT
  • Changing the post type on the home page
    <?php
    
    add_filter( 'pre_get_posts', 'my_get_posts' );
    
    function my_get_posts( $query ) {
    
    	if ( is_home() && false == $query->query_vars['suppress_filters'] )
    		$query->set( 'post_type', array( 'post', 'page', 'album', 'movie', 'quote', 'attachment' ) );
    
    	return $query;
    }
    
    ?>
    

    copy | embed

    0 comments - tagged in  posted by sawyer on Aug 03, 2010 at 10:26 a.m. EDT
  • query custom post types
    <ul>
    
    <?php global $wp_query;
    $wp_query = new WP_Query("post_type=albums&post_status=publish");
    
    while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
        <li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
    <?php endwhile; ?>
    </ul>
    

    copy | embed

    0 comments - tagged in  posted by Titan on Aug 03, 2010 at 9:02 a.m. EDT
  • Custom post types with custom taxonomies in wordpress3
    <?php
    function post_type_albums() {
    	register_post_type(
                         'albums',
                         array('label' => __('Albums'),
                                 'public' => true,
                                 'show_ui' => true,
                                 'supports' => array(
                                            'post-thumbnails',
                                            'excerpts',
                                            'trackbacks',
                                            'comments')
                                    )
                          );
    // Adding the Custom Taxonomy for Genres. Here we can create categories specific for this post type.
    	register_taxonomy( 'genres', 'albums', array( 'hierarchical' => true, 'label' => __('Genres') ) );
    
    // Adding the Custom Taxonomy for Performer. Here we can add tags specific for this post type.
            register_taxonomy( 'performer', 'albums',
    		array(
                             'hierarchical' => false,
    			 'label' => __('Performer'),
    			 'query_var' => 'performer',
    			 'rewrite' => array('slug' => 'performer' )
    		)
    	);
    }
    add_action('init', 'post_type_albums');
    
    ?>
    

    copy | embed

    0 comments - tagged in  posted by Titan on Aug 03, 2010 at 9:01 a.m. EDT
  • create a custom post type in wordpress3
    <?php
    $args = array(
            'label' => __('Products'),
            'singular_label' => __('Product'),
            'public' => true,
            'show_ui' => true,
            'capability_type' => 'page',
            'hierarchical' => false,
            'rewrite' => true,
            'query_var' => 'products',
            'supports' => array('title', 'thumbnail')
    );
    register_post_type( 'product' , $args );
    ?>
    

    copy | embed

    0 comments - tagged in  posted by Titan on Aug 03, 2010 at 9:01 a.m. EDT
  • WordPress category
    <?php
    //WordPress categorie parent binnenhalen
    
    $category = get_the_category();
    $parent = get_cat_name($category[0]->category_parent);
    $parentID = get_cat_ID($parent);
    ?>
    

    copy | embed

    0 comments - tagged in  posted by aphichat on Jul 29, 2010 at 3:26 p.m. EDT
Sign up to create your own snipts, or login.