Skip to content

Instantly share code, notes, and snippets.

@raaar
raaar / php
Created October 13, 2012 14:27
WORDPRESS: the_content with strip tags
<?php
ob_start();
the_content(''.__('Read more <span class="meta-nav">&raquo;</span>', 'sandbox').'');
$old_content = ob_get_clean();
$new_content = strip_tags($old_content, '<img><p><b><br /><input><form><img><textarea><li><ol><ul><table>');
echo $new_content;
?>
@raaar
raaar / php
Created October 13, 2012 15:28
WORDPRESS: remove uneeded menus from admin
function remove_menus () {
global $menu;
$restricted = array(__('Posts'), __('Links'), __('Pages'), __('Comments') );
end ($menu);
while (prev($menu)){
$value = explode(' ',$menu[key($menu)][0]);
if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
}
}
add_action('admin_menu', 'remove_menus');
@raaar
raaar / gist:3973056
Created October 29, 2012 11:29
WORDPRESS - Set Custom post type as HOMEPAGE
add_filter( 'pre_get_posts', 'my_get_posts' );
function my_get_posts( $query ) {
if ( is_home() )
$query->set( 'post_type', array( 'ale' ) );
return $query;
}
@raaar
raaar / gist:5764269
Created June 12, 2013 10:31
Display thumbnail if present, or alternative content
<?php if (has_post_thumbnail( $post->ID ))
{
$image_url = wp_get_attachment_image_src(get_post_thumbnail_id(),'large', true);
echo '<div class="news-thumb" style="background-image: url(' . $image_url[0] . ')"></div>';
}
else
{
echo '<div class="news-thumb" style="background-image: url('. get_bloginfo('template_directory') .'/images/logo-footer.png)"></div>';
}
@raaar
raaar / gist:6201221
Created August 10, 2013 17:12
Wordpress - Query Posts
<?php
$args = array(
'post_type'=> 'work'
);
query_posts( $args );
// The Loop
while ( have_posts() ) : the_post();
echo '<li>';
@raaar
raaar / php
Created August 29, 2013 14:11
INCLUDE PHP
<?php
include($_SERVER['DOCUMENT_ROOT']."/practical-property/parts/footer.php");
?>
@raaar
raaar / gist:6394661
Created August 30, 2013 21:54
WORDPRESS - Add loop in any page
<?php
query_posts( array( 'post_type' => 'discography', 'recordings' => 'live' ) );
if ( have_posts() ) : while ( have_posts() ) : the_post();
?>
<h3><?php the_title(); ?></h3>
<?php the_content(); ?>
<?php endwhile; endif; wp_reset_query(); ?>
@raaar
raaar / javascript
Created September 16, 2013 14:18
JAVASCRIPT: Disable scrolling
// left: 37, up: 38, right: 39, down: 40,
// spacebar: 32, pageup: 33, pagedown: 34, end: 35, home: 36
var keys = [37, 38, 39, 40];
function preventDefault(e) {
e = e || window.event;
if (e.preventDefault)
e.preventDefault();
e.returnValue = false;
@raaar
raaar / html
Created November 1, 2013 13:53
SVG fallback
<img alt="..." src="images/logo.svg" onerror="this.onerror=null; this.src='images/logo.png'"/>