Custom excerpt length
The following WordPress snippets will allow you to set custom except length
1 2 3 4 5 6 7 8 9 |
// Custom excerpt length function custom_excerpt_length( $length ) { return 50; } add_filter( 'excerpt_length', 'custom_excerpt_length', 999 ); |
Source: Snipplr
Update WordPress URL
Adding the following snippet to function.php file will let you update WordPress URL
1 2 3 4 5 6 7 |
<?php update_option('siteurl','http://EURE-SITE.de/'); update_option('home','http://EURE-SITE.de/'); ?> |
Source: Snipplr
get Custom post page name
The following snippet will allow you to have custom post page name
1 2 3 4 5 |
<?php $post_type = get_post_type_object( get_post_type($post) ); echo $post_type->labels->singular_name ; ?> <a href="<? echo(get_page_link(get_page_by_title('Custom post page name')->ID)) ?>">Find out More</a> |
Source: Snipplr
Change role access to Menus and Widgets
Adding the following snippet to functions.php will let you change role access to Menus and Widgets
1 2 3 4 5 6 7 8 9 10 11 |
<?php // get the the role object $role_object = get_role('editor'); // add $cap capability to this role object $role_object->add_cap('edit_theme_options'); ?> |
Source: WP-Snippet
Automatically Notify Your Members on New Posts
The following snippet will send an email to all registered users whenever a post is published
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
function email_members($post_ID) { //global $wpdb; //$usersarray = $wpdb->get_results("SELECT user_email FROM $wpdb->users;"); $wp_user_search = new WP_User_Query( array( 'fields' => array('user_email') ) ); $usersarray = $wp_user_search->get_results(); $arrUsers = array (); for ($arr = $usersarray, $mU = count ($arr), $iU = 0; $iU < $mU; $iU++) { $arrUsers[] = $arr[$iU]->user_email; } // for $users = implode(",", $arrUsers); mail($users, "New post notification : " . get_bloginfo('name') , "A new post has been published on " . get_bloginfo('siteurl') ); return $post_ID; } add_action('publish_post', 'email_members'); |
WordPress, page hook
Using the following snippet will let you change the code on the page which you are on
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
<?php $url = $_SERVER['REQUEST_URI']; $tokens = explode('/', $url); $part = $tokens[sizeof($tokens)-2]; if($part == "page-one") { echo '<img src="image1.jpg" />'; } elseif($part == "page-two") { echo '<img src="image2.jpg" />'; } else { //Nothing here aka error } ?> |
Source: Novastream
Alert Shortcodes
The following snippet will alert shortcodes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
// Alert Shortcodes function alert_green($atts, $content = null) { return'<div class="alert-green">' . $content . '</div>'; } add_shortcode('alert_green', 'alert_green'); function alert_blue($atts, $content = null) { return'<div class="alert-blue">' . $content . '</div>'; } add_shortcode('alert_blue', 'alert_blue'); function alert_yellow($atts, $content = null) { return'<div class="alert-yellow">' . $content . '</div>'; } add_shortcode('alert_yellow', 'alert_yellow'); function alert_red($atts, $content = null) { return'<div class="alert-red">' . $content . '</div>'; } add_shortcode('alert_red', 'alert_red'); /* Alert Shortcodes */ /* Buttons, message boxes, & alert boxes */ .alert-green { -moz-border-radius:3px; -webkit-border-radius:3px; border-radius:3px; background:#e5ffcc url(images/alert_green.png) left center no-repeat; color:#573; border:1px solid #bbdd99; padding:10px 10px 10px 40px; margin:10px 0 20px 0; } .alert_blue { -moz-border-radius:3px; -webkit-border-radius:3px; border-radius:3px; background:#e5f5ff url(images/alert_blue.png) left center no-repeat; color:#467; border:1px solid #bde; padding:10px 10px 10px 40px; margin:10px 0 20px 0; } .alert_yellow { -moz-border-radius:3px; -webkit-border-radius:3px; border-radius:3px; background:#ffd url(images/alert_yellow.png) left center no-repeat; color:#664; border:1px solid #ddc; padding:10px 10px 10px 40px; margin:10px 0 20px 0; } .alert_red { -moz-border-radius:3px; -webkit-border-radius:3px; border-radius:3px; background:#fcc url(images/alert_red.png) left center no-repeat; color:#744; border:1px solid #daa; padding:10px 10px 10px 40px; margin:10px 0 20px 0; } |
Source: Snipplr