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

Include a file

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

<?php include(TEMPLATEPATH . ‘/includes/featured.php’); ?> If using a child theme use STYLESHEETPATH instead <?php include(STYLESHEETPATH . ‘/includes/featured.php’); ?>

Include a fileRead More

Category: Code Snippets

Show all errors

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

if you get the white screen in WordPress, try this in wp-config.php but keep it commented out most of the time to hide misc. errors from normal viewers define(‘WP_DEBUG’, true);

Show all errorsRead More

Category: Code Snippets

MENU – show class in wp_list_pages for links that have kids

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

This comes in handy if you are using a list_page menu and need to change the style of menu elements that have children, liks add an arrow. This needs to be in the functions file. add_filter(‘page_css_class’, ‘nice_navigation_page_css_class’, 10, 2); /** * adds class “page-has-children” to all pages that have children * @param array $class. The page css class being modified, passed as an array from Walker_Page * @param object $page. The page object passed from Walker_Page * @return array Returns the new page css class. */ function nice_navigation_page_css_class($class, $page) { // check if current page has children $children = get_pages(‘child_of=’.$page->ID); …

MENU – show class in wp_list_pages for links that have kidsRead More

Category: Code Snippets

Show Logged in User Info

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

<?php global $current_user; get_currentuserinfo(); echo ‘Username: ‘ . $current_user->user_login . “n”; echo ‘User email: ‘ . $current_user->user_email . “n”; echo ‘User first name: ‘ . $current_user->user_firstname . “n”; echo ‘User last name: ‘ . $current_user->user_lastname . “n”; echo ‘User display name: ‘ . $current_user->display_name . “n”; echo ‘User ID: ‘ . $current_user->ID . “n”; ?>

Show Logged in User InfoRead More

Category: Code Snippets

Show all sql errors

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

add this right after the sql statement line $wpdb->show_errors();  

Show all sql errorsRead More

Category: Code Snippets

Use a shortcode in a template

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

<?php do_shortcode(‘[shortcode]’); ?>

Use a shortcode in a templateRead More

Category: Code Snippets

Update a single row in the db.

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

<?php $wpdb->query( ” UPDATE $wpdb->posts SET post_parent = 7 WHERE ID = 15 AND post_status = ‘static’ ” ); ?>

Update a single row in the db.Read More

Category: Code Snippets

Blog Info Tags

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

Usually needed for displaying the stylesheet directory for use in file paths, put lots of other good uses as well Format <?php bloginfo(‘stylesheet_directory’); ?> Complete List – follow the same format as above name                 = Testpilot description          = Just another WordPress blog admin_email          = admin@example url                  = https://example/home wpurl                = https://example/home/wp stylesheet_directory = https://example/home/wp/wp-content/themes/child-theme stylesheet_url       = https://example/home/wp/wp-content/themes/child-theme/style.css template_directory   = https://example/home/wp/wp-content/themes/parent-theme template_url         = https://example/home/wp/wp-content/themes/parent-theme atom_url             = https://example/home/feed/atom rss2_url             = https://example/home/feed rss_url              = https://example/home/feed/rss pingback_url         = https://example/home/wp/xmlrpc.php rdf_url              = https://example/home/feed/rdf comments_atom_url    = https://example/home/comments/feed/atom comments_rss2_url    = https://example/home/comments/feed charset              = UTF-8 html_type            = text/html language             = en-US text_direction       = ltr version              = 3.1

Blog Info TagsRead More

Category: Code Snippets

Show All Query Vars

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

This is great for troubleshooting. If you need to see the main variables WP is loading, try sticking this in your template and refreshing. For more info, try this without the ->query_vars at the end. <pre><?php print_r($wp_query->query_vars); ?></pre>

Show All Query VarsRead More

Category: Code Snippets

List Subpages

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

This is great for custom sub nav of pages <?php // list the About subpage menu $args=array( ‘showposts’=>5, // how many to show ‘sort_column’=>’menu_order’, ‘post_type’=>’page’, // page or post ‘child_of’ => $post->ID, ); $myPosts = get_pages($args); if ($myPosts) { foreach ($myPosts as $myPage) { $permalink = get_permalink($myPage->ID); } } ?>

List SubpagesRead More

Category: Code Snippets

Display Content of a post or page anywhere

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

This is useful if you have a place on the sidebar or a box on the homepage where you want to have some changeable content. Add the content to a post or page and then output it wherever you want it using this. <?php // know the id of the page you want to display $theId = 668; // get the post $feature = get_post($theId); // get the content for the post. You can also get anything else for the post, post_title, post_excerpt… $content = $feature->post_content; echo $content; ?>

Display Content of a post or page anywhereRead More

Category: Code Snippets

Outputting array elements from query_vars

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

If you use <pre><?php print_r($wp_query->query_vars); ?></pre> to display the query var array and decide to use one of the elements, here are some simple examples the get_query_var() function that outputs them. <?php $curcat = get_query_var(‘category_name’); $curtax = get_query_var(‘taxonomy’); $curterm = get_query_var(‘term’); ?>  

Outputting array elements from query_varsRead More

Category: Code Snippets

Custom Database Query – WP Style

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

Get just about anything and display it. <?php $sql = “SELECT event_begin, event_end, event_title, event_short FROM wp_my_calendar ORDER BY event_begin LIMIT 3”; $holidays = $wpdb->get_results($sql); if ($holidays) { foreach ($holidays as $holiday) { $eventstart = $holiday->event_start; } ?>

Custom Database Query – WP StyleRead More

Category: Code Snippets

Simple Mail Function

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

<?php wp_mail(‘jcamomile@pobox.com’, ‘test’, ‘The message’); ?>

Simple Mail FunctionRead More

Category: Code Snippets

Remove a filter

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

If you want to prevent a plugin or function from working on this template only, you can use this to remove the filter. Of course you need to find out the name of the filter first. This can be done by looking for the the add_filter functions in  plugin. The example below removes the st_add_widget (share this) from the content <?php remove_filter(‘the_content’, ‘st_add_widget’); ?>

Remove a filterRead More

Category: Code Snippets

Echo Custom Field (Post Meta)

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

<?php echo get_post_meta($post->ID, ‘customfield’, true); ?>

Echo Custom Field (Post Meta)Read More

Category: Code Snippets

What Template am I in?

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

Use in functions php.  It outputs the name of the template file being used to display the current page. add_action(‘wp_head’, ‘show_template’); function show_template() { global $template; print_r($template); }

What Template am I in?Read More

Category: Code Snippets

Check if user is Admin

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

Make something visible or invisible depending on whether logged in user is admin: <?php if ( is_user_logged_in() && current_user_can(‘manage_options’) ) { do_something(); } ?>

Check if user is AdminRead More

Category: Code Snippets

Links List (bookmarks) Advanced

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

Need to List a bunch of links, aka bookmarks, aka blogroll … This code comes in handy <?php $args = array( ‘orderby’ => ‘name’, ‘order’ => ‘ASC’, ‘limit’ => -1, ‘category’ => , ‘category_name’ => , ‘hide_invisible’ => 1, ‘show_updated’ => 0, ‘include’ => , ‘exclude’ => , ‘search’ => ); ?> <?php $bookmarks = get_bookmarks( $args ); // Loop through each bookmark and print formatted output foreach ( $bookmarks as $bm ) { printf( ‘<a class=”relatedlink” href=”%s”>%s</a><br />’, $bm->link_url, __($bm->link_name) ); } ?>

Links List (bookmarks) AdvancedRead More

Category: Code Snippets

Hide Development Code before publishing

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

Cute way to partition off code that you are working on so that normal users don’t see it but you do. Simply add this conditional around your test code. Then on the test page, add ?iam=testing to the end of the url. <?php if ($_GET[‘iam’]==’testing’){ // code you are testing } ?>

Hide Development Code before publishingRead More

Category: Code Snippets

  • « Go to Previous Page
  • 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 © 2026 · Stormhill Media All Rights Reserved.
Website by Stormhill Media
Log in