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
WordPress WP_ Settings
The snippet let you set some WordPress directories / paths directly to the server name.
1 2 3 4 5 6 7 |
define('WP_SITEURL', 'http://' . $_SERVER['SERVER_NAME'] . '/wordpress'); define('WP_HOME', 'http://' . $_SERVER['SERVER_NAME']); define('WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/wp-content'); define('WP_CONTENT_URL', 'http://' . $_SERVER['SERVER_NAME'] . '/wp-content'); |
Source: Snipplr
Access Request URI for template reuse
The following snippet will let you access request URI for template reuse
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<?php switch ($wp->request) { case 'directory': get_template_part('content', 'directory'); break; case 'history': get_template_part('content', 'history'); break; default: get_template_part('content', 'default'); }; ?> |
Source: Kovshenin
WordPress Widget Basic Stucture
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 |
<?php error_reporting(E_ALL); /* Plugin Name: Messenger Widget Plugin URI: http://www.scoldy.com Description: Any message designated. Version: 1.0 Author: Ronnie Author URI: http://www.scoldy.com */ class Messager extends WP_Widget { function __construct() { } public function form() { } public function widget() { } } ?> |
Source: Snipplr
WordPress Child Theme
The following snippet will let you sort out the stylesheet
1 2 3 4 5 6 7 8 9 10 11 12 13 |
/* Theme Name: Child Theme Name Description: Description of your Child Theme Author: Your name here Template: folder */ @import url("../parentthemefolder/style.css"); |
Source: doitwithwp.com
Custom Menus in WordPress
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
register: <?php register_nav_menus( array( 'primary' => __( 'Primary Navigation', 'primarynav' ), 'secondary' => __( 'Secondary Navigation', 'secondarynav' ), 'footer' => __( 'Footer Navigation', 'footernav' ), ) ); ?> display: <?php wp_nav_menu(array( 'theme_location' => 'footer')); ?> |
Source: Snipplr
SQL query to delete all media and attachments
The following snippet will delete all media in the library and remove all post attachments.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# First: DELETE FROM wp_postmeta WHERE post_id IN ( SELECT id FROM wp_posts WHERE post_type = 'attachment' ) ; # Second: DELETE FROM wp_posts WHERE post_type = 'attachment' |
Source: WordPress.org
Simple iframe shortcode
Using the snippet will let you take iframe parameters and build an iframe through a shortcode
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
add_shortcode('iframe', 'iframe'); function iframe($atts) { extract(shortcode_atts(array( 'src' => "", 'width' => "800", 'height' => "600" ), $atts)); $iframe = '<iframe src="'.$src.'" width="'.$width.'" height="'.$height.'" scrolling="no" allowtransparency="yes" frameborder="0" ></iframe>'; return $iframe; } |
Source: Snipplr
Disable the WordPress file editor
The following snippet will disable the WordPress file editor
1 |
define('DISALLOW_FILE_EDIT', TRUE); |
Automatically link Twitter usernames
Paste the snippet in the function.php file of your theme and it will let you automatically link Twitter usernames
1 2 3 4 5 6 7 8 9 10 11 12 13 |
/* automatically link Twitter usernames in WordPress*/ function twtreplace($content) { $twtreplace = preg_replace('/([^a-zA-Z0-9-_&])@([0-9a-zA-Z_]+)/',"$1<a href=\"http://twitter.com/$2\" target=\"_blank\" rel=\"nofollow\">@$2</a>",$content); return $twtreplace; } add_filter('the_content', 'twtreplace'); add_filter('comment_text', 'twtreplace'); |
Source: Snipplr
Search Posts by Custom Post Type
The snippet will let you search posts by custom post types
1 2 3 4 5 6 7 8 9 10 11 |
<? /* Template Name: Search Results */ $search_refer = $_GET["post_type"]; if ($search_refer == 'CUSTOM_POST_TYPE') { load_template(TEMPLATEPATH . '/template_one-name.php'); } elseif ($search_refer == 'CUSTOM_POST_TYPE') { load_template(TEMPLATEPATH . '/template_two-name.php'); }; ?> |
Source: WP-Snipp
Photo Credit: Flickr/Brad Montgomery