https://madebydenis.com/adding-google-fonts-to-your-wordpress-theme/
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!)
Vertical Align Anything
.parent-element { -webkit-transform-style: preserve-3d; -moz-transform-style: preserve-3d; transform-style: preserve-3d; } .element { position: relative; top: 50%; transform: translateY(-50%); } Credit
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
Hacks to Enhance WP Search Engine
Helpful Responsive Web Design Links
Converting WordPress to Be Mobile-Friendly Building a Mobile First Responsive WordPress Theme Responsive Design in 3 Steps How to Turn Any Site Into a Responsive Site Choosing Fonts for Your Mobile Website Super useful jQuery plugins for responsive web design Especially: Tinynav.js and jQuery Masonry
Remove the “read more” jump
On WordPress blogs, when you click on a “Read more” link, it automatically drops to the point in the article you theoretically just got to the end of. If you don’t really like that jump, simply paste the following code into your functions.php file to get rid of it. function wdc_no_more_jumping($post) { return ‘<a… Continue reading Remove the “read more” jump
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
CSS “content” property
CSS has a property called content. It can only be used with the pseudo elements :after and :before. It is written like a pseudo selector (with the colon), but it’s called a pseudo element because it’s not actually selecting anything that exists on the page but adding something new to the page. This is what… Continue reading CSS “content” property
Automatically add classes to links generated by next_posts_link and previous_posts_link
add_filter(’next_posts_link_attributes’, ‘posts_link_attributes’); add_filter(’previous_posts_link_attributes’, ‘posts_link_attributes’); function posts_link_attributes() { return ‘class="myclass"’; }
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”]
Dynamic date for copyright notices
echo date(’Y’);
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
Block spam via .htaccess
RewriteEngine On RewriteCond %{REQUEST_METHOD} POST RewriteCond %{REQUEST_URI} .wp-comments-post\.php* RewriteCond %{HTTP_REFERER} !.*yourdomainname.com.* [OR] RewriteCond %{HTTP_USER_AGENT} ^$ RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]