How To Redirect Users To A Random Post
Using the following snippet, you will be able to redirect users to a random post.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
// set arguments for get_posts() $args = array( 'numberposts' => 1, 'orderby' => 'rand' ); // get a random post from the database $my_random_post = get_posts ( $args ); // process the database request through a foreach loop foreach ( $my_random_post as $post ) { // redirect the user to the random post wp_redirect ( get_permalink ( $post->ID ) ); exit; } |
Snippet Source/Credit: Smashing Magazine
How To Add A Logo To A Template
Using the following snippet, you will be able to add a logo to a template.
1 |
<img src="<?php echo get_stylesheet_directory_uri()?>/images/logo.png" alt="My Logo"> |
Snippet Source/Credit: WPSnipp
How To Set A Maximum Word Count On Post Titles
Adding the following snippet to your theme’s functions.php file, you will be able to set a maximum word count on post titles.
1 2 3 4 5 6 7 |
function maxWord($title){ global $post; $title = $post->post_title; if (str_word_count($title) >= 10 ) //set this to the maximum number of words wp_die( __('Error: your post title is over the maximum word count.') ); } add_action('publish_post', 'maxWord'); |
Snippet Source/Credit: Pippin
How To Delete Links In Comments In WordPress
Using the following snippet, you will be able to delete links in comments in WordPress.
1 2 3 4 5 6 |
function delete_comment_link($id) { if (current_user_can('edit_post')) { echo '| <a href="'.get_bloginfo('wpurl').'/wp-admin/comment.php?action=cdc&c='.$id.'">borrar</a> '; echo '| <a href="'.get_bloginfo('wpurl').'/wp-admin/comment.php?action=cdc&dt=spam&c='.$id.'">spam</a>'; } } |
Snippet Source/Credit: Snipplr