WP Smith

Creating WordPress & Genesis Websites Since 2010

  • Home
  • About
  • Services
  • Blog
  • Contact

Mar 13 2012

Get Genesis Comments in a Shortcode

Recently, I corresponded with someone who need to port the Genesis comments into a shortcode for a custom post type template (I'm assuming). However, doing it seemed challenging and a lot of hack work, but he reminded me of the genesis template part, which made it very doable.

Since I thought this was fairly novel idea, I thought I'd post about here.

[php]
remove_action( 'genesis_after_post', 'genesis_get_comments_template' );

function ts_genesis_comments_shortcode() {
ob_start();
genesis_get_comments_template();
$tsComments = ob_get_clean();
return $tsComments;
}
add_shortcode ('ts-genesis-comments', 'ts_genesis_comments_shortcode');
[/php]

First we need to remove the comments template via remove_action( 'genesis_after_post', 'genesis_get_comments_template' );. Then we can get the comments via output buffering (ob_start() and ob_get_clean()).

Written by Travis Smith · Categorized: Genesis

Mar 05 2012

How to Move the Comment Form Above the Comments List in Genesis

This is extremely easy and only involves only a few lines of code that can go into functions.php.

[php]
add_action( 'genesis_before_comments' , 'wps_post_type_check' );
function wps_post_type_check () {
if ( is_single() ) {
if ( have_comments() ) {
remove_action( 'genesis_comment_form', 'genesis_do_comment_form' );
add_action( 'genesis_list_comments', 'genesis_do_comment_form' , 5 );
}
}
}
[/php]

If you do not check for comments, then simply removing the form and adding it at the top of the list will remove the form altogether on single pages/posts that have no comments. We do this with a simple function, have_comments().

Written by Travis Smith · Categorized: Genesis

Mar 05 2012

How to Embed Videos at Different Sizes in Genesis (and other Themes)

Need to embed videos but hate the limitation that you cannot have the same post appear with the same video on different sizes? WordPress provides a little known filter (embed_defaults) that will enable you to easily change the height and width of an embeded object.


Currently, WordPress allows oEmbed by default, and it supports the following sites:

  • YouTube (only public videos and playlists - "unlisted" and "private" videos will not embed)
  • Vimeo
  • DailyMotion
  • blip.tv
  • Flickr (both videos and images)
  • Viddler
  • Hulu
  • Qik
  • Revision3
  • Scribd
  • Photobucket
  • PollDaddy
  • WordPress.tv (only VideoPress-type videos for the time being)
  • SmugMug (WordPress 3.0+)
  • FunnyOrDie.com (WordPress 3.0+)
  • Twitter (WordPress 3.4+)

For any of these videos, you can support multiple widths so that the video is "full" content width. For example, check out these examples:

  • Video on my site on full-width
  • Video on my site on sidebar-content-sidebar
  • Video on my site on sidebar-content

So how did I do this? In HTML mode, I inserted the url

http://www.youtube.com/watch?v=R2a8TRSgzZY

and clicked publish. Then in my functions.php file, I have this code:

*NOTE: In Genesis 1.8, this function will break the blog page template due to a bug that will hopefully be fixed in the next version.

In this function, we are filtering a WordPress function wp_embed_defaults() that creates default array of embed parameters when do_shortcode is used (which is applied to the_content).

For other themes, the code would be modified to use the standard WordPress conditionals.

Written by Travis Smith · Categorized: Genesis

Feb 14 2012

How to Hide the Featured Image of a Specific Category on the Blog Page in Genesis

So, in case you forgot, in Genesis Featured Images can be added to the blog page by selecting the checkbox "Include the Featured Image?" in Genesis > Theme Settings > Content Archives (admin url: http://domain.com/wp-admin/admin.php?page=genesis#genesis-theme-settings-posts).

Genesis Content Archives
Click for Larger Image

So what if you wanted to remove the featured images of a specific category (say category ID 126 [to get the category ID, use a plugin called Simply Show IDs--makes it quite easy!])?

Here is what I did:

  1. Copied page_blog.php from the genesis directory, which only contains genesis() function call.
  2. Then added the following function.

[php]
add_action( 'genesis_before_post' , 'wps_no_feature_image' );
add_action( 'genesis_after_post_content' , 'wps_no_feature_image' );
/*
* Remove Featured Image from Small Group Show category on blog page
* @author Travis Smith
*
*/
function wps_no_feature_image() {
global $post;

if ( has_category( 126 , $post ) && 'genesis_before_post' == current_filter() )
remove_action( 'genesis_post_content', 'genesis_do_post_image' );
elseif ( has_category( 126 , $post ) && 'genesis_after_post_content' == current_filter() )
add_action( 'genesis_before_post_content', 'genesis_do_post_image' );
}
[/php]

First and foremost, we cannot simply remove the action and keep going because then it will be unhooked for all categories on that page after. So what's happening here?

Now, the Genesis Featured Image appears on the genesis_post_content hook. So I need to call my function before that hook (or earlier in priority) to remove that action. So I call the function on genesis_before_post which occurs before genesis_post_content. Then after I pass genesis_post_content hook, I need to add the action back for the next post.

So, if I am illustrating this, it's as though I am walking down the hallway approaching a hook with a hat that I was going to put on my head. Before I get to the hook, my brother takes the hat, and after I pass the hook, my brother puts the hat back on the hook for the next person.

Written by Travis Smith · Categorized: Genesis

Feb 09 2012

How to Enable Genesis Author Boxes Automatically for ALL Users

In Genesis there are two ways to do this: there is the direct filter or the simple function call. Calling the function calls the filter, so either way the filter is being called.

To enable the Author Box you can add the following to your functions.php file.
[php]
// Enable Author Box on Single/Archive pages
add_filter( 'get_the_author_genesis_author_box_single', '__return_true' );
add_filter( 'get_the_author_genesis_author_box_archive', '__return_true' );
[/php]

Or, the Genesis way to do this is:
[php]
// Enable Author Box on Single/Archive pages
genesis_enable_author_box();
genesis_enable_author_box( array( 'type' => 'archive' ) );
[/php]

Written by Travis Smith · Categorized: Genesis

  • « Previous Page
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • …
  • 20
  • Next Page »
  • Twitter
  • Facebook
  • LinkedIn
  • Google+
  • RSS

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