Skip to content

Instantly share code, notes, and snippets.

@Clorith
Clorith / gist:5254369
Created March 27, 2013 14:02
WordPress default .htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress_clean/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress_clean/index.php [L]
</IfModule>
<?php
function breadcrumbs() {
if( ! is_home() ){
global $post;
?>
<a href="<?php bloginfo( 'wpurl' ); ?>">Home</a> &raquo;
<?php $parent = $post->post_parent;
$parent_title = get_the_title( $parent );
echo '<a href="'.get_permalink( $parent ) .'">' . $parent_title . ( '' ); ?> </a> &raquo;
<?php the_title( '' ); ?>
<?php
function create_rewrites() {
add_rewrite_rule(
'pamelding/([^/]+)/?$',
'index.php?pagename=pamelding&courseid=$matches[1]',
'top'
);
add_rewrite_rule(
'kursdetaljer/([^/]+)/([^/]+)/?$',
'index.php?pagename=kursdetaljer&courseid=$matches[1]',
d.iframe.one("load", function () {
f = true;
if (g) {
e.resolveWith(d)
} else {
setTimeout(function () {
e.rejectWith(d, ["ready timeout"])
}, d.sensitivity)
}
});
jQuery(document).ready(function($){
var _custom_media = true,
_orig_send_attachment = wp.media.editor.send.attachment;
$('#myMediaArea').click(function(e) {
var send_attachment_bkp = wp.media.editor.send.attachment;
var button = $(this);
var id = button.attr('id').replace('_button', '');
_custom_media = true;
@Clorith
Clorith / gist:5701123
Created June 3, 2013 20:29
wordpress custom rewrite rules
<?php
function theme_rewrites( $wp_rewrite ) {
$rules = array(
'coordinates/([^/]+)/?$' => 'index.php?pagename=coordinates&coords=$matches[1]',
);
$wp_rewrite->rules = array_merge( $rules, $wp_rewrite->rules );
}
add_action( 'generate_rewrite_rules', 'theme_rewrites' );
<?php
function theme_custom_post_type() {
$labels = array(
'name' => _x( 'Clues', 'post type general name' ),
'singular_name' => _x( 'Clue', 'post type singular name' ),
'add_new' => _x( 'Add', 'book' ),
'add_new_item' => __( 'Add clue' ),
'menu_name' => __( 'Clues' )
);
$args = array(
@Clorith
Clorith / gist:6152213
Created August 4, 2013 22:30
WordPress hook and function to display various posts and custom post types on author pages
/*
* Function for modifying the main query
*/
function modify_the_loop( $query ) {
// Check that this is the main query, not a secondary one, and trigger if it's the author page'
if ( $query->is_main_query() && $query->is_author() )
{
$query->set( 'post_type', array( 'post', 'page', 'CPT', 'CPT2' ) );
}
}
@Clorith
Clorith / gist:6218138
Created August 13, 2013 05:26
Quickie on using forms in WordPress
function my_post_check()
{
if ( isset( $_POST['myslug-name'] ) )
{
Do form stuff here
}
}
add_action( 'init', 'my_post_check' );
$fetched = '21082013';
date_default_timezone_set( 'UTC' );
$date = DateTime::createFromFormat( 'dmY', $fetched );
echo $date->format( 'Y-m-d' );