Using Woo Canvas and probably all woo themes with their custom framework, you will run into strange things from time to time.. If you try to use pre_get_posts to filter the query of posts in the blog homepage, you find that it doesnt work. So here is a way I found to do it: // Exclude categories on the “Blog” page template. add_filter( ‘woo_blog_template_query_args’, ‘change_posts_per_page’, 10 ); function change_posts_per_page( $args ) { global $woo_options; if ( isset($woo_options[‘woo_posts_limit’]) && !empty($woo_options[‘woo_posts_limit’]) ){ $args[‘posts_per_page’] = $woo_options[‘woo_posts_limit’]; } print_r(”); print_r($args); print_r(‘ ‘); return $args; } // End woo_exclude_categories_blogtemplate()
Change post names and guids for blogspot import
when migrating a blog from blogspot to wordpress, and you want to have the incoming links work without making a 301 redirect for each post, you will need to change the way incoming links are handled after being redirected from blogspot Generally, blogspot/blogger urls differ from WordPress in the following ways: 1. the domain name (of course). When redirects are set up at blogspot, the url is changed to the new domain name, and the rest of the url (after the domain) is left the same. If you set up redirection for the blog in blogspot, then this is done. …
add_filter
Quick Simple example of add_filter – sticking something in the bottom of the_content(). // filter to add stuff to the end of content in posts function add_stuff_to_content($content) { global $post; if ( ‘post’ != get_post_type() ) { // limit this to only the post type you want to alter return $content; //exit; } $original = $content; $morestuff .= ‘<div class=”stuff”>Extra Stuff!!</div>’; $thecontent = $original.$morestuff; // puts more stuff right after post return $thecontent; } add_filter(the_content, add_stuff_to_content);
Footer Credits
Standard Code for Footer credits. This one is for author websites. For Business ones, use Umstattdmedia.com instead for the link: <p> © <?php echo date(‘Y’); ?> <?php bloginfo(); ?> | Site Built by <a target=”_blank” href=”https://www.authormedia.com” rel=”nofollow”>Author Media</a> </p>
add to allowed upload types
This goes in the functions if you need to allow other file types to upload to the library. The example adds two e-book formats. // add types to allowed uploads add_filter(‘upload_mimes’, ‘custom_upload_mimes’); function custom_upload_mimes ( $existing_mimes=array() ) { // add the file extension to the array $existing_mimes[‘epub’] = ‘mime/type’; $existing_mimes[‘prc’] = ‘mime/type’; // call the modified list of extensions return $existing_mimes; }
Show What Template You are In
Here is cool little functionto stick in functions to help you see which template you are viewing when looking at a page in the browser. It simply shows the template file name in the footer. It is based on a plugin called “What Template” but has the improved feature of only working when you are logged in as admin. if ( is_user_logged_in() && current_user_can(‘manage_options’) ) { add_action(‘wp_footer’, ‘show_template’); } function show_template() { global $template; print_r($template); } ?>
Remove Meta Box from Admin Form (post, page, custom)
Hides meta boxes in admin forms as needed. 1. This is great for when a plugin adds a metabox to your post or page form and you want to hide it. 2. the tricky part is finding the name of the box – as with the magicmembersdiv box in example below. You can usually find this by searching the plugin for the add_meta_box() call where they add the box – i.e. add_meta_box(‘magicmemberdiv, ‘….’,’…….’,…) // hide admin meta boxes that we are not using function remove_themeta_box() { remove_meta_box( ‘magicmemberdiv’, ‘post’, ‘side’ ); remove_meta_box( ‘magicmemberdiv’, ‘page’, ‘side’ ); remove_meta_box( ‘magicmemberdiv’, ‘homepage’, ‘side’ …
Remove Meta Box from Admin Form (post, page, custom)Read More
WP Redirect
wp_redirect() is a cool way to redir someone based on certain circumstances, like user permissions. So far I have seen this help in two applications. 1. use just the at the top of template file to redirect a page to another page if user is logged in. I.E. – if you want to redirect a logged in user away from this page to another…. if(is_user_logged_in()) { wp_redirect(“/member-profile/”); exit(); } 2. use in functions to redirect logged in users to other member page if they are not admins. Then you can hook it in the action of entering the admin (admin_init) …
Installing a Favicon in WordPress
From: https://codex.wordpress.org/Creating_a_Favicon Installing a Favicon in WordPress If there is already an old favicon.ico file in your current theme’s main folder, delete it using FTP Clients. With an FTP Client, upload the new favicon.ico file into your current theme’s main folder. Upload another copy of your favicon.ico file to the main directory of your site (ie. https://example.com/favicon.ico). This will display the favicon in your subscribers’ feedreaders. In order for your favicon to show up in some older browsers, you will need to edit your page header. go to header.php in your theme to edit the file. Search for the line …
Add a class to the Body Class
So you need to add a class to the body classes to get stuff to work right. Here is a way to do it. Also, change woocommerce-page to something useful to you. function mlp_add_a_filter($classes){ $classes[]=”woocommerce-page”; return $classes; } add_filter(‘body_class’,’mlp_add_a_filter’); If you know you are using PHP 5.3 or above, here is a quicker way add_filter(‘body_class’,function($classes){$classes[]=”woocommerce-page”;return $classes;});
Change Stylesheet and Initialscale for Android Browsers
To make stuff work in Android you can use this function in the header.php 1. This replaces the call to the default stylesheet, so if you use this, you need to take out the normal stylesheet line. 2. Most of the heavy lifting seems to be happening with adjusting the initialscale in the viewport meta tag. The biggest issue we have found with Android deals with initialscale. Changing it to 0.25 seemed to make it load the full screen. Though really small it is what most clients seem to want. 3.That said, the function also loads a separate stylesheet for …
Change Stylesheet and Initialscale for Android BrowsersRead More
Wysiwyg Output via ‘Custom Fields’
//Get_post_meta(); with the parameters of the post/page id you’re pulling from, the name you gave the element, and ‘true’. /*this example is used for everything else. */ $sidetitle = get_post_meta($theId, ‘book_sidebar’, true); /*to pull from a Wysiwyg and retain formating, put wpautop(); around get_post_meta(); */ $sidetxt = wpautop(get_post_meta($theId, ‘sidebar_txt’, true));
Search and Replace String
This is a good string to use in the sql section of phpmyadmin when replacing strings Note that the table name is used once and the table field is used twice in each query example for search replace in wp_posts update wp_posts set post_content = replace(post_content,’lifetalkcafe.com’,’hallattorneys.com’); example in postmeta update wp_posts set guid = replace(guid,’lifetalkcafe.com’,’hallattorneys.com’); Update 7/19/12 Jim found a cool script to search and replace and not break serialized strings. https://interconnectit.com/124/search-and-replace-for-wordpress-databases/
Mobile Header.php
<?php /** * The Header for our theme. * * Displays all of the <head> section and everything up till <div id=”main”> * * @package WordPress * @subpackage Twenty_Eleven * @since Twenty Eleven 1.0 */ global $is_iphone; if ( $is_iphone || $_GET[‘iam’]==’testing’ ) { include( STYLESHEETPATH . ‘/mobile/header.php’ ); } else { include( STYLESHEETPATH . ‘/inc_header.php’ ); } ?> Basically, the proper way to use $is_iphone. This example uses it to call two different header.php include files, but it could be used to call different css files or different template files, or whatever, basically. inc_header.php is the default header.php for …
Mullet
// /* This code goes in index.php */ <?php if ( have_posts() ) : ?> <?php /* Our Mullet Function begins here – Katie Suess 12/28/11 */ $classnum = count(get_body_class()); /* fetch body classes */ $classarr = get_body_class(); /* make it a testable variable */ for ($i = 0; $i <= $classnum; $i++) { $bodyclass = $classarr[$i]; if ($bodyclass == paged) { $excerpt_trigger = 1; /* No Mullet on Deeper Pages */ break 1; /* exit the while */ } else { $excerpt_trigger = 0; /* Set Count For Mullet */ } } ?> <?php /* Start the Loop */ …
Manual Canonical Redirects
If you need to make sure non-www links end up on www… #Options +FollowSymLinks RewriteEngine on RewriteCond %{HTTP_HOST} ^yoursite.com [NC] RewriteRule ^(.*)$ https://www.yoursite.com/$1 [L,R=301]
Show Featured Image
after setting featured image. parameter size accepts thumbnail, medium, large or custom eg. array(230,234) <?php $theattr = array( ‘src’ => $src, ‘class’ => “attachment-$size”, ‘alt’ => trim(strip_tags( $attachment->post_excerpt )), ‘title’ => trim(strip_tags( $attachment->post_title )), ); the_post_thumbnail( ‘large’, $theattr ); ?>
get a single row from a table in the db
versatile way to get single piece of info related to something you already have $user = $wpdb->get_row($wpdb->prepare(“SELECT * FROM $wpdb->users WHERE user_activation_key = %s AND user_login = %s”, $key, $login)); if ( !empty( $user ) ){ $username = $user->name; }
Truncate Text
put in functions to truncate a post excerpt or something <?php function ttruncat($text,$numb) { if (strlen($text) > $numb) { $text = substr($text, 0, $numb); $text = substr($text,0,strrpos($text,” “)); $etc = ” …”; $text = $text.$etc; } return $text; } ?>
WP Nav Menu
place a nav menu anywhere <?php $navargs = array( ‘theme_location’ => , ‘menu’ => , ‘container’ => ‘div’, ‘container_class’ => , ‘container_id’ => , ‘menu_class’ => ‘menu’, ‘menu_id’ => , ‘echo’ => true, ‘fallback_cb’ => ‘wp_page_menu’, ‘before’ => , ‘after’ => , ‘link_before’ => , ‘link_after’ => , ‘depth’ => 0, ‘walker’ => ); ?> <div class=”access”> <?php wp_nav_menu($navargs); ?> </div>