This website uses cookies to remember you and improve your experience. For more info see our Privacy Policy.

  • About
  • Websites
    • Business Websites
    • Author Websites
  • SEO
  • Portfolio
    • Author Web Design
    • Business Web Design
    • Custom Graphics
    • Logos
  • Services & Pricing
    • Author Website Packages
    • Website Hosting
    • Page Speed Optimization
    • SEO
    • Local SEO
  • MyBookTable
    • MyBookTable Support
  • Contact
  • Hire Us

Mobile Menu

  • Menu
  • Skip to right header navigation
  • Skip to main content

Stormhill Media

Custom websites for every type of business

Header Right

  • About
  • Websites
    • Business Websites
    • Author Websites
  • SEO
  • Portfolio
    • Author Web Design
    • Business Web Design
    • Custom Graphics
    • Logos
  • Services & Pricing
    • Author Website Packages
    • Website Hosting
    • Page Speed Optimization
    • SEO
    • Local SEO
  • MyBookTable
    • MyBookTable Support
  • Contact
  • Hire Us

Code Snippets

Home » Code Snippets

Change Number of Posts on Posts page in Woo Canvas

by Daniel Camomile · In: Code Snippets · on Apr 18, 2013

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 Number of Posts on Posts page in Woo CanvasRead More

Category: Code Snippets

Change post names and guids for blogspot import

by Daniel Camomile · In: Code Snippets · on Dec 5, 2012

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. …

Change post names and guids for blogspot importRead More

Category: Code Snippets

add_filter

by Daniel Camomile · In: Code Snippets · on Jul 12, 2012

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);

add_filterRead More

Category: Code Snippets

Footer Credits

by Daniel Camomile · In: Code Snippets · on Jun 18, 2012

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>

Footer CreditsRead More

Category: Code Snippets

add to allowed upload types

by Daniel Camomile · In: Code Snippets · on Apr 24, 2012

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; }

add to allowed upload typesRead More

Category: Code Snippets

Show What Template You are In

by Daniel Camomile · In: Code Snippets · on Apr 19, 2012

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); } ?>

Show What Template You are InRead More

Category: Code Snippets

Remove Meta Box from Admin Form (post, page, custom)

by Daniel Camomile · In: Code Snippets · on Apr 2, 2012

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

Category: Code Snippets

WP Redirect

by Daniel Camomile · In: Code Snippets · on Mar 28, 2012

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) …

WP RedirectRead More

Category: Code Snippets

Installing a Favicon in WordPress

by Daniel Camomile · In: Code Snippets · on Mar 20, 2012

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 …

Installing a Favicon in WordPressRead More

Category: Code Snippets

Add a class to the Body Class

by Daniel Camomile · In: Code Snippets · on Mar 19, 2012

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;});

Add a class to the Body ClassRead More

Category: Code Snippets

Change Stylesheet and Initialscale for Android Browsers

by Daniel Camomile · In: Code Snippets · on Mar 15, 2012

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

Category: Code Snippets

Wysiwyg Output via ‘Custom Fields’

by Daniel Camomile · In: Code Snippets · on Mar 12, 2012

//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));

Wysiwyg Output via ‘Custom Fields’Read More

Category: Code Snippets

Search and Replace String

by Daniel Camomile · In: Code Snippets · on Feb 23, 2012

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/

Search and Replace StringRead More

Category: Code Snippets

Mobile Header.php

by Daniel Camomile · In: Code Snippets · on Feb 23, 2012

<?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 …

Mobile Header.phpRead More

Category: Code Snippets

Mullet

by Daniel Camomile · In: Code Snippets · on Feb 20, 2012

// /* 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 */ …

MulletRead More

Category: Code Snippets

Manual Canonical Redirects

by Daniel Camomile · In: Code Snippets · on Feb 20, 2012

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]

Manual Canonical RedirectsRead More

Category: Code Snippets

Show Featured Image

by Daniel Camomile · In: Code Snippets · on Feb 20, 2012

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 ); ?>

Show Featured ImageRead More

Category: Code Snippets

get a single row from a table in the db

by Daniel Camomile · In: Code Snippets · on Feb 19, 2012

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; }

get a single row from a table in the dbRead More

Category: Code Snippets

Truncate Text

by Daniel Camomile · In: Code Snippets · on Feb 19, 2012

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; } ?>

Truncate TextRead More

Category: Code Snippets

WP Nav Menu

by Daniel Camomile · In: Code Snippets · on Feb 19, 2012

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>

WP Nav MenuRead More

Category: Code Snippets

  • Page 1
  • Page 2
  • Page 3
  • Go to Next Page »

Site Footer

Quick Links:

  • Contact Us
  • Pricing & Services
  • Sitemap
  • Terms/Conditions
  • Privacy Policy
  • Business Websites
  • Author Websites
  • SEO Services
(903) 213-5266‬

Copyright © 2025 · Stormhill Media All Rights Reserved.
Website by Stormhill Media
Log in