IT Nota

  • Home
  • How To
  • .NET
  • WordPress
  • Contact

How to Add ID Attribute in Genesis Main Content

With the upgrade of Genesis Framework to responsive design, there’s a particular id attribute on the web content that’s deprecated when you use HTML5. If you take a look at /genesis/lib/framework.php file from Genesis core, you will see that the id="content" markup is still included in the XHTML markup. However for HTML5, the ID attritube is no longer there.

genesis_markup( array(
     'html5'   => '<main %s>',
     'xhtml'   => '<div id="content" class="hfeed">',
     'context' => 'content',
) );

This change creates a problem for some custom javascript to make Google AdSense responsive. The easiest thing to do is just to modify framework.php file to look like this:

genesis_markup( array(
     'html5'   => '<main id="content" %s>',
     'xhtml'   => '<div id="content" class="hfeed">',
     'context' => 'content',
) );

But obviously this is the worst thing to do because any future updates on Genesis core will overwrite that modification. So we want to make the change on the Genesis child theme instead.

Fortunately Genesis markup is very easy to modify. We just need to apply filter within the context of any section we want to change. In this case, it’s the content and we just need to do this on the Genesis child theme functions.php file.

// Add id="content" attributes to <main> element
add_filter( 'genesis_attr_content', 'my_attr_content' );
function my_attr_content( $attr ) {

     $attr['id'] .= 'content';
     return $attr;
    
}

The flexibility of filter in Genesis Framework is not limited to what’s shown in this example. You can also create custom schema for anything on your site by using the same method.

Further Reading

Custom microdata with Genesis 2.0

July 5, 2014 Filed Under: How To, WordPress Tagged With: Genesis Framework

Migrating Genesis Metadata to Yoast SEO

If you install Yoast’s WordPress SEO Plugin on top of your Genesis theme, you’ll notice that all your manually typed meta descriptions (and maybe keywords) just went completely missing. Meta description is an important element for search engine to index your pages and when you already have more than hundreds of pages and posts or even ten, then re-typing is definitely not an option.

Since I’m not aware of any way to do this from the plugin, the easiest way to do this is on the database.

Again as a forewarning, before you attempt to do this, backup everything in your MySQL to make sure you can revert back if you make a mistake. The solution is quick and simple, but it’s so easy to make a mistake that will corrupt your data and possibly more.

Go to your SQL admin interface such as phpMyAdmin (or you can do command line interface if you prefer) and run these sql commands:

UPDATE wp_postmeta
SET meta_key = '_yoast_wpseo_metadesc'
WHERE meta_key = '_genesis_description';

UPDATE wp_postmeta
SET meta_key = '_yoast_wpseo_metakeywords'
WHERE meta_key = '_genesis_keywords';

Here’s how it looks on phpMyAdmin panel:
MySQL's phpMyAdmin SQL commands

You have to make sure that there aren’t any typos whatsoever on the value you need to assign on the meta_key or else you need to restore the database from the backup and start over.

These sql statements were tested on WordPress SEO version 1.4.24 and Genesis Framework 2.0.2. If you use older or newer versions of both software, you need to verify the meta_key if they’re still using the same values.

January 29, 2014 Filed Under: WordPress Tagged With: Genesis Framework, SQL

How to Add Pagination on Genesis Lifestyle Theme Front Page

Genesis Lifestyle Pro Theme
As an update to their top seller Genesis Theme, StudioPress released a new Lifestyle Pro Theme with responsive design and HTML5. If you’re a member of My StudioPress, then you’ll have access to setup the theme exactly as it looks like in a demo, which is already very good to begin with.

I really like how the front page was setup, however I also want it to function as my main blog along with navigation links at the bottom of the content (see picture). Genesis standard loop is still going to be used for page two and beyond so they look like a normal blog page.

In order to achieve this, we need to modify the front-page.php file. The modification was based on the code from Bill Erickson for creating custom loop with pagination.

See the modified front-page.php below with all changes highlighted.

<?php
/**
 * This file adds the Home Page to the Lifestyle Pro Theme.
 *
 * @author StudioPress
 * @package Lifestyle Pro
 * @subpackage Customizations
 */

add_action( 'genesis_meta', 'lifestyle_home_genesis_meta' );
/**
 * Add widget support for homepage. If no widgets active, display the default loop.
 *
 */
function lifestyle_home_genesis_meta() {

	if ( !is_paged() ) {

		if ( is_active_sidebar( 'home-top' ) || is_active_sidebar( 'home-middle' ) || is_active_sidebar( 'home-bottom-left' ) || is_active_sidebar( 'home-bottom-right' ) ) {
	
			// Force content-sidebar layout setting
			add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_content_sidebar' );
	
			// Add lifestyle-pro-home body class
			add_filter( 'body_class', 'lifestyle_body_class' );
	
			// Remove the default Genesis loop
			remove_action( 'genesis_loop', 'genesis_do_loop' );
	
			// Add homepage widgets
			add_action( 'genesis_loop', 'lifestyle_homepage_widgets' );

		}
	}
}

function lifestyle_body_class( $classes ) {

	$classes[] = 'lifestyle-pro-home';
	return $classes;
	
}

function lifestyle_homepage_widgets() {
	
	genesis_widget_area( 'home-top', array(
		'before' => '<div class="home-top widget-area">',
		'after'  => '</div>',
	) );
	
	genesis_widget_area( 'home-middle', array(
		'before' => '<div class="home-middle widget-area">',
		'after'  => '</div>',
	) );
	
	if ( is_active_sidebar( 'home-bottom-left' ) || is_active_sidebar( 'home-bottom-right' ) ) {

		echo '<div class="home-bottom">';

		genesis_widget_area( 'home-bottom-left', array(
			'before' => '<div class="home-bottom-left widget-area">',
			'after'  => '</div>',
		) );

		genesis_widget_area( 'home-bottom-right', array(
			'before' => '<div class="home-bottom-right widget-area">',
			'after'  => '</div>',
		) );
		
		echo '</div>';	
	}

	// Based on https://gist.github.com/billerickson/3218052
	global $post;
	// arguments, adjust as needed
	$args = array(
				'post_type' => 'post',
				'posts_per_page' => get_option( 'posts_per_page' ),
				'post_status' => 'publish',
				'paged' => get_query_var( 'paged' )
			);

	/*
	Overwrite $wp_query with our new query.
	The only reason we're doing this is so the pagination functions work,
	since they use $wp_query. If pagination wasn't an issue,
	use: https://gist.github.com/3218106
	*/
	
	global $wp_query;
	$wp_query = new WP_Query( $args );
		 
	if ( have_posts() ) :
		while ( have_posts() ) : the_post();
		endwhile;
		
		do_action( 'genesis_after_endwhile' );			
	endif;

	wp_reset_query();
}

genesis();

The pagination on the front page should look like the picture below.

Genesis Lifestyle Pro Theme Custom Pagination

Lifestyle Pro is definitely worth checking out due to its capability as one of the modern responsive WordPress themes, its elegant look, and easy customization.

Caveat

You need to pay attention on the number posts to show on the Admin settings. Since the way it’s setup on the front page is showing 8 posts at a time, you need to make sure the setting is also for 8 posts at a time so the second page of the blog doesn’t skip any postings.

WordPress Admin Setup (Reading)

January 13, 2014 Filed Under: How To, WordPress Tagged With: Genesis Framework

How to Add Footer to a Custom Post Type in Genesis 2.0

When you create a single or an archive page for a custom post type in Genesis 2.0 (HTML5), the formatting is not consistent with typical post. What’s apparent is the absence of <footer class="entry-footer"> tag in the custom post type page.

The difference between the two are highlighted on the codes below:
Custom Post Type

<p class="entry-meta">
  <span class="entry-categories">
    Filed Under:
    <a rel="category tag" title="View all posts in Uncategorized" href="https://www.itnota.com/category/uncategorized">Uncategorized</a>
  </span>
  <span class="entry-tags">
    Tagged With:
    <a rel="tag" href="https://www.itnota.com/tag/genesis-framework/">Genesis Framework</a>, 
    <a rel="tag" href="https://www.itnota.com/tag/html5/">HTML5</a>
  </span>
</p>

Typical Post

<footer class="entry-footer">
  <p class="entry-meta">
    <span class="entry-categories">
      Filed Under:
      <a rel="category tag" title="View all posts in Uncategorized" href="https://www.itnota.com/category/uncategorized">Uncategorized</a>
    </span>
    <span class="entry-tags">
      Tagged With:
      <a rel="tag" href="https://www.itnota.com/tag/genesis-framework/">Genesis Framework</a>, 
      <a rel="tag" href="https://www.itnota.com/tag/html5/">HTML5</a>
    </span>
  </p>
</footer>

The easiest way to do this is by utilizing using Genesis Shortcodes and replace the genesis_entry_footer with our own footer markup.

remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_open', 5 );
add_action( 'genesis_entry_footer', 'my_entry_footer_markup_open', 5);
function my_entry_footer_markup_open() {
  echo '<footer class="entry-footer">';
}

add_filter( 'genesis_post_meta', 'my_post_meta' );
function my_post_meta( $post_meta ) {

  $post_meta = '[[post_categories]][[post_tags]]';

  return $post_meta;

}

remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_close', 15 );
add_action('genesis_entry_footer', 'my_entry_footer_markup_close', 15);
function my_entry_footer_markup_close() {
  echo '</footer>';
}

Further Reading

Genesis Framework Shortcode Reference
Function Reference/wp get post tags
Function Reference/wp get post categories

December 21, 2013 Filed Under: How To, WordPress Tagged With: Genesis Framework

How to Use a CDN jQuery in Genesis Framework

As a follow up to my previous post on using a CDN jQuery in your website.

If you use WordPress (with Genesis Framework) and want to take advantage of a CDN (Content Delivery Network) hosted jQuery library to your theme, edit your functions.php file to include these codes:

if ( !is_admin() ) {
  wp_deregister_script('jquery');
  wp_register_script('jquery', 'http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.11.1.min.js', false, '1.11.1');
  wp_enqueue_script('jquery');
}

The codes above will include jQuery CDN on your site, but not the fallback method mentioned in this post. To implement a similar fallback solution in WordPress/Genesis, just add these lines into your functions.php in your child theme directory:

// De-register default jQuery from WordPress
if (!is_admin()) {  
  wp_deregister_script('jquery');  
}

// Replace DOCTYPE to HTML5 and include CDN-hosted jQuery and fallback method
remove_action('genesis_doctype', 'genesis_do_doctype');
add_action('genesis_doctype', 'child_do_doctype');
function child_do_doctype() { ?>
  <!DOCTYPE html>
  <html <?php language_attributes(); ?>>
    <head profile="http://gmpg.org/xfn/11">
    <meta charset="<?php bloginfo('charset'); ?>" />
    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.1.min.js"></script>
    <script>!window.jQuery && document.write('<script src="/js/jquery-1.11.1.min.js"></script>')</script>
<?php
} 
...

This will not only add the jQuery CDN and a fallback method, but also replaces the DOCTYPE heading to HTML5 in your Genesis Theme.

One caution before you do this. Make sure all plugins, especially the old ones, are tested for compatibility with the jQuery version you want to use.

All the above examples use jQuery library hosted on Microsoft CDN. If you want to use other CDN hosts, just change the URL address in the src tag. For example, to use jQuery from Google CDN, you have to use this address instead (everything else should be the same):

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

Update

With the newer version of WordPress and Genesis, the better and easier way to do this is just to de-register the default jQuery in function.php using the following codes:

// De-register default jQuery from WordPress
if ( !is_admin() ) {  
  add_action( 'wp_print_scripts', 'de_script', 100 );

  function de_script() {
    wp_dequeue_script( 'jquery' );
    wp_deregister_script( 'jquery' );

    wp_register_script('jquery', '//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js', false, 1.11.1, true);
    wp_enqueue_script('jquery');
  }
}

The last parameter true will add the jquery in the footer instead of header, which is a better way for performance sake.

Genesis Framework Theme Settings wp_footer() CDN jQuery

Further Reading

Function Reference/wp register script
Function Reference / wp dequeue script

February 7, 2012 Filed Under: Coding, How To, WordPress Tagged With: Genesis Framework, HTML5

Next Page »
Buy me a coffee Support this site
Buy Me a Coffee?

Categories

  • .NET
  • Coding
  • Cybersecurity
  • Database
  • How To
  • Internet
  • Multimedia
  • Photography
  • Programming
  • Resources
  • Review
  • Tips and Tricks
  • Uncategorized
  • Use Case
  • WordPress
  • Writing

Recent Posts

  • How to View Stored Procedure Code in SQL Server
  • How to Find a String in SQL Server Stored Procedures
  • How to Remove Cached Credentials without Rebooting Windows
  • ESP Work Automation: Empowering Enterprises with Streamlined Workflows and Operational Efficiency
  • How to Search for a String in All Tables in a Database

Recent Posts

  • How to View Stored Procedure Code in SQL Server
  • How to Find a String in SQL Server Stored Procedures
  • How to Remove Cached Credentials without Rebooting Windows
  • ESP Work Automation: Empowering Enterprises with Streamlined Workflows and Operational Efficiency
  • How to Search for a String in All Tables in a Database

Tags

.NET .NET Core AdSense ASP.NET Cdonts Dll Classic ASP Code Editor ETL FSharp Genesis Framework Git Google HP Asset Manager HTML5 Hugo IIS Information Security Internet Internet Information Services iOS JAMStack Linux macOS Microsoft Microsoft SQL Server MVC PHP PowerShell Python Simple Mail Transfer Protocol Smtp Server SQL SQL Server SSIS SSMS SSRS Sublime Text Visual Studio Visual Studio Code VPN Windows Windows 8 Windows 10 Windows 2012 Windows Server

Copyright © 2011-2025 IT Nota. All rights reserved. Terms of Use | Privacy Policy | Disclosure