WP Smith

Creating WordPress & Genesis Websites Since 2010

  • Home
  • About
  • Services
  • Blog
  • Contact

Mar 04 2011

Javascript (JS) to Footer Except…

YSlow! recommends that you move Javascript to the footer. However, not all cases lend itself to move one's JS to the footer. So here is a quick and easy way to do this in functions.php. For one of my sites running with Shopp, I needed the javascript (js) to run in the header as running it in the footer disabled the buttons. So here is what I did to fix my Shopp problem with Views buttons.

[php]//JS in header for Shopp else in footer
$pages = array('store','account','checkout','cart'); //these are the 4 pages created by default by Shopp
if (is_page(!$pages)) {
remove_action('wp_head', 'wp_print_scripts');
remove_action('wp_head', 'wp_print_head_scripts', 9);
remove_action('wp_head', 'wp_enqueue_scripts', 1);
add_action('wp_footer', 'wp_print_scripts', 5);
add_action('wp_footer', 'wp_enqueue_scripts', 5);
add_action('wp_footer', 'wp_print_head_scripts', 5);
}
[/php]

So, if it is not one of my Shopp pages, then I run the scripts in my footer.

Written by Travis Smith · Categorized: Tutorials

Mar 03 2011

Post Formats in WordPress 3.1: Checking for Theme Support and Adding Theme Support

With WordPress 3.1, Post Formats were added, which makes WordPress a hybrid between its traditional CMS/blog environment and Tumblr's quick posting format. This cross or hybrid makes WordPress much more powerful and flexible.

To check to see whether the current theme supports post formats use the following conditional to do nothing if the theme does not support post formats:
[php]if ( !current_theme_supports( 'post-formats' ) || !function_exists( 'get_post_format' ) )
return;[/php]

Or with Genesis:
[php]if ( !current_theme_supports( 'post-formats' ) || !current_theme_supports( 'genesis-post-format-images' ) || !function_exists( 'get_post_format' ) )
return;[/php]

To add theme support for post formats, you will need to add the following:
[php]add_theme_support( 'post-formats', array( 'aside', 'chat', 'gallery', 'image', 'link', 'quote', 'status', 'video' ) );[/php]

For Genesis child themes, you'll need to add an additional theme support which is used in the genesis function, genesis_do_post_format_image().
[php]add_theme_support( 'genesis-post-format-images' );[/php]

Written by Travis Smith · Categorized: Genesis

Mar 02 2011

Remove Post Title and Page Title from Genesis Child Theme (with or without Post Formats Support)

The same function controls the title for posts and pages; however, to remove the title from one or the other is different. As always open the functions.php in your favorite html/text editor or at Appearance > Editor (or in MS, found under Network Admin). Scroll to the bottom of the page and paste the code below into the functions.php file.

Remove Post Title from Posts

To remove all titles from posts, simply add the following:
[php]//REMOVE POST TITLE
remove_action('genesis_post_title', 'genesis_do_post_title');[/php]

With the introduction of Post Formats in WordPress 3.1, depending on its format, you may want to remove the post title. As it currently stands, has_post_format($arg1, $arg2) can only take a string in $arg1 and $arg2 is optional (and is $post_id), and the supported post formats from WordPress 3.1 are: aside, chat, image, link, quote, status, video, audio, and gallery. So to remove post titles from posts with these formats, simply add the following:
[php]if ( has_post_format( 'aside' ) || has_post_format( 'chat' ) || has_post_format( 'image' ) || has_post_format( 'link' ) || has_post_format( 'quote' ) || has_post_format( 'status' ) || has_post_format( 'video' ) || has_post_format( 'audio' ) || has_post_format( 'gallery' ) ) {
remove_action('genesis_post_title', 'genesis_do_post_title');[/php]

Remove Post Title from Pages

To remove page titles from specific pages, simply add the following:
[php]//REMOVE PAGE TITLE
add_action('get_header', 'child_remove_page_titles');
function child_remove_page_titles() {
$pages=array();
if (is_page($pages)) {
remove_action('genesis_post_title', 'genesis_do_post_title');
}
}[/php]

Or, to remove the title from the home page, simply add the following:
[php]//REMOVE PAGE TITLE FROM HOME PAGE
add_action('get_header', 'child_remove_page_titles');
function child_remove_page_titles() {
if (is_home()) {
remove_action('genesis_post_title', 'genesis_do_post_title');
}
}[/php]

Written by Travis Smith · Categorized: Genesis

Mar 01 2011

How to Find Out What Functions Do In WordPress (& Elsewhere) Using Text Editor like Notepad++

So it became apparent to me as I kept asking people and searching the WordPress Codex where such and such function was defined or used. Now, I have a process that I have refined over time that I want to share. It may not be the best process but it works and works well.

First, as with any web design or development, you need a good text editor. I use Notepad++ since I haven't forked over for a Mac (anyone who wishes to buy me one, please feel free!). Plus Notepad++ is free!

So for example, say I am looking over nav-menus.php from the WordPress core. On line 67, I come across a function called wp_get_object_terms(); So if I want to know what this is, I do one of two things or sometimes both.

  1. First, search the WordPress Codex.
  2. Second, search the WordPress Core Code (online or off).

In this example, the Codex has good information. However, sometimes (though rare) you will see that the Codex is not completely filled out or brought up-to-date or easy to understand without seeing the function.

With the second option, I typically used Yoast's PHPXref (ensuring that I am searching the correct WordPress version) until I was on a plane recently and refused to pay the $10 bucks for wifi since I had everything on my laptop. So then I turned to my text editor. (In the past, I used Windows XP with indexing to find such files; however, I'm now running Windows 7 and the search functions are horrible [and I haven't taken the time to try to figure out what's wrong with Windows 7 search ability or how to improve it]).

So if you open Notepad++, the third menu item is Search. If you click Find in Files a search menu will appear.

Finding WordPress Functions with NotePad++
Click Image for Larger Image

If you hit Ctrl+F as I often do, then select the tab that says Find in Files. Fill in function wp_get_object_terms in the Find what: input box, since I want to find where it's defined to see its accepted variables so I can use it. Then I select the file structure that I want it to search, so you could select the entire WordPress install so it searches wp-admin, wp-includes, and wp-content or just pick one of those folders.

Finding WordPress Functions with NotePad++
Click Image for Larger Image

A quick search reveals that this function is defined in taxonomy.php in the wp-includes folder. The great thing about the search is that it typically returns the entire line that its found, so NotePad++ told me what I was looking for:

function wp_get_object_terms($object_ids, $taxonomies, $args = array()) {

.

Finding WordPress Functions with NotePad++
Click Image for Larger Image

So if I want to see the entire function to try to determine what the function does or returns if anything, I need to open the file. While Notepad++ finds the function, it's not a simple click and open that file. So I have to navigate to the file, open it and go to line 1778 to see the full function. One of the great things about WordPress is that there are a lot of comments informing the user what the function does. For this one particular function, there are 30 lines about this function including the following vital information:

 * @package WordPress
 * @subpackage Taxonomy
 * @since 2.3.0
 * @uses $wpdb
 *
 * @param int|array $object_ids The ID(s) of the object(s) to retrieve.
 * @param string|array $taxonomies The taxonomies to retrieve terms from.
 * @param array|string $args Change what is returned
 * @return array|WP_Error The requested term data or empty array if no terms found. WP_Error if $taxonomy does not exist.

This tells me that $object_ids is either an integer or an array of integers; $taxonomies is a string or an array of strings, and $args is an array of strings that can affect what is returned. It also tells me that this function returns an array or a WP_Error message.

Finding WordPress Functions with NotePad++
Click Image for Larger Image

 

So now, there's an offline version or way to search your WordPress files for function calls, function definitions, etc.

Written by Travis Smith · Categorized: WordPress

Feb 28 2011

Add the Genesis Author Box to Pages

The Genesis tutorials tells how to set up Author Boxes, how to style Author Boxes, and how to add Author Boxes to Author Archive Pages.

As it currently stands, the author box can only be added to the author archive pages and the single post pages. And from what I see, it doesn't appear on pages like http://domain.com/page-name but does appear on http://domain.com/category/post-name. However, what if I wanted to have the author box appear on all the pages or just some or not on some. Well, here's how to do it.

To insert the author box on ALL pages:
[php]/** Add Genesis Author Box on Single Pages**/
add_action('genesis_after_post', 'genesis_do_author_box_page');
function genesis_do_author_box_page() {
if ( !is_page() )
return;

if ( get_the_author_meta( 'genesis_author_box_single', get_the_author_meta('ID') ) ) {
genesis_author_box( 'single' );
}

}[/php]

To insert the author box on ALL pages except...
[php]/** Add Genesis Author Box on Single Pages**/
add_action('genesis_after_post', 'genesis_do_author_box_page');
function genesis_do_author_box_page() {
$page_exclusions = array(42,'about-me','Contact'); //edit these pages, can take slugs, page names, or page/post ID
if ( ( !is_page() ) || is_page($page_exclusions) )
return;

if ( get_the_author_meta( 'genesis_author_box_single', get_the_author_meta('ID') ) ) {
genesis_author_box( 'single' );
}

}[/php]

To insert the author box on only certain pages:
[php]/** Add Genesis Author Box on Single Pages**/
add_action('genesis_after_post', 'genesis_do_author_box_page');
function genesis_do_author_box_page() {
$page_inclusions = array(42,'about-me','Contact'); //edit these pages, can take slugs, page names, or page/post ID
if ( is_page($page_inclusions) ) {
if ( get_the_author_meta( 'genesis_author_box_single', get_the_author_meta('ID') ) ) {
genesis_author_box( 'single' );
}
}
else
return;

}[/php]

Written by Travis Smith · Categorized: Genesis, Tutorials

  • « Previous Page
  • 1
  • …
  • 52
  • 53
  • 54
  • 55
  • 56
  • …
  • 61
  • Next Page »
  • Twitter
  • Facebook
  • LinkedIn
  • Google+
  • RSS

Copyright © 2025 � WP Smith on Genesis on Genesis Framework � WordPress � Log in