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
Displaying WordPress Excerpt Dynamic Length
The following snippet display the WordPress excerpt dynamic length.
1 2 3 4 5 6 7 8 9 10 11 12 |
function ms_rp_excerpt($limit) { $excerpt = explode(' ', get_the_excerpt(), $limit); if (count($excerpt) >= $limit) { array_pop($excerpt); $excerpt = implode(' ', $excerpt).'...'; } else { $excerpt = implode(' ', $excerpt); } $excerpt = preg_replace('`\[[^\]]*\]`', '', $excerpt); return $excerpt; } |
Snippet Source/Credit: Snipplr
Delete Width And Height Attributes From Image Tag
The following snippet will let you delete both width and height attributes from image tag.
1 2 3 4 5 |
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'thumbnail' ); if ($image) : ?> <img src="<?php echo $image[0]; ?>" alt="" /> <?php endif; ?> |
Snippet Source/Credit: Stackexchange
How To Set Basic Tag Cloud In WordPress
The following line of code will let you set basic tag cloud in WordPress.
1 |
<?php wp_tag_cloud('smallest=8&largest=16&'); ?> |
How To Know That Which Theme You Are Using
Adding the following lines of code will let you know that which theme you are using.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
add_action( 'wp_head', 'show_me_the_template' ); function show_me_the_template() { global $template, $current_user, $wp_admin_bar; get_currentuserinfo(); /* If you have more than one user deny. Be sure to use your user ID! */ if ( !is_user_logged_in() && $current_user->ID != '1' ) return; if ( is_admin_bar_showing() ) $wp_admin_bar->add_menu( array( 'parent' => false, 'id' => 'template', 'title' => $template, 'href' => '#' )); else print_r( $template ); } |
Snippet Source/Credit: Snipplr
How To Change Editor Font In WordPress
The following snippet will let you change editor font in WordPress.
1 2 3 4 5 |
add_action( 'admin_head-post.php', 'devpress_fix_html_editor_font' ); add_action( 'admin_head-post-new.php', 'devpress_fix_html_editor_font' ); function devpress_fix_html_editor_font() { ?> <style type="text/css">#editorcontainer #content, #wp_mce_fullscreen { font-family: Georgia, "Times New Roman", "Bitstream Charter", Times, serif; }</style> <?php } |
Snippet Source/Credit: DevPress