Setting Up WP Customizer

https://madebydenis.com/setting-wordpress-customization-api-up/ Adding custom controls: https://madebydenis.com/adding-custom-controls-to-your-customization-api/

Paged WP_query (That works!)

<?php // set up or arguments for our custom query $paged = ( get_query_var(’paged’) ) ? get_query_var(’paged’) : 1; $query_args = array( ‘post_type’ => ‘post’, ‘category_name’ => ‘tutorials’, ‘posts_per_page’ => 5, ‘paged’ => $paged ); // create a new instance of WP_Query $the_query = new WP_Query( $query_args ); ?>   <?php if ( $the_query->have_posts() )… Continue reading Paged WP_query (That works!)

Registering/Enqueing Scripts in functions.php

  if (!is_admin()) { wp_deregister_script(’jquery’); wp_register_script(’jquery’, ("http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"), false); wp_enqueue_script(’jquery’); wp_register_script(’hoverIntent’, get_bloginfo(’template_directory’) . ‘/js/hoverIntent.js’, null, null, false); wp_enqueue_script(’hoverIntent’); wp_register_script(’superfish’, get_bloginfo(’template_directory’) . ‘/js/superfish.js’, null, null, false); wp_enqueue_script(’superfish’); wp_register_script(’slider’, get_bloginfo(’template_directory’) . ‘/js/slider.js’, null, null, false); wp_register_script(’cycle’, get_bloginfo(’template_directory’) . ‘/js/jquery.cycle.js’, null, null, false); }   function pp_conditional_script_loading() { if ( is_home() || is_category(’900’) || is_page (’page-slug’ ) || is_post_type_archive(’post_type’)… Continue reading Registering/Enqueing Scripts in functions.php

Post Type rewrite rules

Nest a page under a post type archive:   function my_rewrite_rules_array( $rules ) { $rules = array_merge( array( ‘post-type/pagename/?$’ => ‘index.php?pagename=post-type/pagename’, ), $rules );   return $rules; } add_filter( ‘rewrite_rules_array’, ‘my_rewrite_rules_array’ ); Nest a second post type under a main post type:   function my_rewrite_rules( $rules ) { $newrules = array(); $newrules[’^.*/second-post-type-slug/([^/]+)$’] = ‘index.php?your_post_type=$matches[1]&post_type=your_post_type’; return… Continue reading Post Type rewrite rules

Prevent automatic image compression

By default, WordPress compress jpg images when you upload them to your blog. This is useful because it saves bandwidth and loading time, but sometimes you may prefer to have full quality images (For example, if you’re a photographer using WordPress to showcase your work). Paste the code below into your functions.php file to remove… Continue reading Prevent automatic image compression

Remove Microsoft Word HTML tags

The following function takes some nightmarish Word HTML and return a clean HTML output that you can use safely on the web. function cleanHTML($html) { $html = ereg_replace("<(/)?(font|span|del|ins)[^>]*>","",$html);   $html = ereg_replace("<([^>]*)(class|lang|style|size|face)=("[^"]*"|'[^’]*’|[^>]+)([^>]*)>","<\1>",$html); $html = ereg_replace("<([^>]*)(class|lang|style|size|face)=("[^"]*"|’[^’]*’|[^>]+)([^>]*)>","<\1>",$html);   return $html }

Shortcode for TTF Titles

function the_ttftext_shortcode( $atts ) { extract( shortcode_atts( array( ‘text’ => ”, ‘echo’ => false, ‘style’ => ”, ‘overrides’ => ”, ), $atts ) );   return the_ttftext (esc_attr($text), false, esc_attr($style), esc_attr($overrides)); } add_shortcode(’ttf_text’, ‘the_ttftext_shortcode’); [ttf_text text=”Hello World!” style=”basic”]

Sub-categories inherit the parent category template

  function szub_cat_template_inherit() { if(is_category()) { global $wp_query; $category = $wp_query->get_queried_object();   if( $category->category_parent && file_exists(TEMPLATEPATH . ‘/category-‘ . $category->category_parent . ‘.php’) ) $template = TEMPLATEPATH . ‘/category-‘ . $category->category_parent . ‘.php’; elseif( file_exists(TEMPLATEPATH . "/category-" . get_query_var(’cat’) . ‘.php’) ) $template = TEMPLATEPATH . "/category-" . get_query_var(’cat’) . ‘.php’; elseif( file_exists(TEMPLATEPATH . "/category.php") )… Continue reading Sub-categories inherit the parent category template

Embed a PDF in an iframe

This is definitely the easiest way to display a PDF file on your website: The PDF is loaded through Google docs and then displayed in an iframe, on your own site. To use this shortcode, first paste the code below into your functions.php file:   function cwc_viewpdf($attr, $url) { return ‘<iframe src="http://docs.google.com/viewer?url=’ . $url .… Continue reading Embed a PDF in an iframe

Members only content

If you want to create some private content that only registered users are able to see, the following shortcode is the solution to your problem. Paste the code below into your functions.php file in order to create the shortcode:   function cwc_member_check_shortcode( $atts, $content = null ) { if ( is_user_logged_in() && !is_null( $content )… Continue reading Members only content

Obfuscate email addresses

As most of you know, spam bots are constantly scanning the internet in order to find emails to spam. Of course, you don’t want to receive spam, but what if you need to display your email (or someone else) on your blog? This code will create a shortcode which will obfuscate email adresses. As usual,… Continue reading Obfuscate email addresses

Fix a Fatal Memory Error

If you see this error either suddenly (no specific task was done to cause the error) or frequently, try deactivating all plugins to rule-out a plugin-specific issue and try switching themes to rule-out a theme-specific issue. Specific fixes: 1. If you’re using WordPress 2.9.2 or lower, try adding define(‘WP_MEMORY_LIMIT’, ‘256M’); to your wp-config.php file. If… Continue reading Fix a Fatal Memory Error

Create Your Own Loop With WP_Query

<?php $recentPosts = new WP_Query(); $recentPosts->query(’showposts=5’); ?>   <?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?> <!– do some stuff here –> <?php endwhile; ?> With Pagination: <?php $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query(); $wp_query->query(’showposts=5′.’&paged=’.$paged); ?> <!– do some stuff here –> <?php $wp_query = null; $wp_query = $temp; ?>

Improved Excerpt

function improved_trim_excerpt( $text ) { if ( ” == $text ) { $permalink = get_permalink(); // my addition $text = get_the_content( ” ); $text = strip_shortcodes( $text ); $text = apply_filters( ‘the_content’, $text ); $text = preg_replace( ‘@<script[^>]*?> . *?</script>@si’, ”, $text ); $text = str_replace( ‘]]>’, ‘]]>’, $text ); $text = strip_tags( $text, ‘<b><em><i><p><strong><sub><sup><a>’… Continue reading Improved Excerpt

Related posts

<?php //Gets category info global $wp_query; $cats = get_the_category(); $tempQuery = $wp_query; $currentId = $post->ID;   //related category posts $catlist = ""; forEach( $cats as $c ) { if( $catlist != "" ) { $catlist .= ","; } $catlist .= $c->cat_ID; } $newQuery = "posts_per_page=6&orderby=rand&cat=" . $catlist; query_posts( $newQuery ); $categoryPosts = ""; $count =… Continue reading Related posts

Conditional Statements

<?php if ( ) { ?>   <?php } else ( ) { ?>   <?php } ?> Conditional Tags: is_page() is_single() is_category() is_author() is_home() Usage Examples: is_page(‘3’) is_page(‘About Us’’) is_page(‘about-us’) is_category(‘5’) is_category(‘Apples’) is_category(‘apples’) Example #1: Multiple conditions <?php if ( is_page(’Apples’) ) { ?>   <img src="apples.gif" />   <?php } elseif ( is_page(’Oranges’)… Continue reading Conditional Statements

Published
Categorized as PHP