Created
April 13, 2014 02:29
-
-
Save dcondrey/10566424 to your computer and use it in GitHub Desktop.
Boilerplate markup for basic Wordpress index.php. Integrated with HTML5 semantic markup and Schema.org structured data. Miscellaneous other PHP functions that I use in most of my templates can also be found here.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function my_scripts_method() { | |
wp_enqueue_style( 'style', get_stylesheet_uri()); | |
wp_enqueue_style( 'fonts', get_template_directory_uri() . '/css/fonts.css'); | |
wp_deregister_script( 'jquery' ); | |
wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'); | |
wp_enqueue_script( 'jquery' ); | |
wp_enqueue_script( 'social', get_template_directory_uri() . '/js/social.js'); | |
wp_enqueue_script( 'blogjs', get_template_directory_uri() . '/js/blog.js'); | |
} | |
add_action('wp_enqueue_scripts', 'my_scripts_method'); | |
/* Add HTML5_Shiv and Selectivr (combined and minified into ie.js) */ | |
add_action( 'wp_head', create_function( '','echo \'<!--[if lt IE 9]><script src="/js/ie.js"></script><![endif]-->\';')); | |
/* ---------- CANONICALIZATION ---------- */ | |
function seo_canonical() { | |
global $post; | |
remove_action('wp_head', 'rel_canonical'); | |
$canonical = get_bloginfo('url'); | |
if (is_single() || is_page()) { | |
$canonical = get_permalink($post->ID); | |
} else if (is_day()) { | |
$year = get_query_var('year'); | |
$month = get_query_var('year'); | |
$day = get_query_var('day'); | |
$canonical = get_year_link($year, $month, $day); | |
} else if (is_month()) { | |
$year = get_query_var('year'); | |
$month = get_query_var('monthnum'); | |
$canonical = get_year_link($year, $month); | |
} else if (is_year()) { | |
$year = get_query_var('year'); | |
$canonical = get_year_link($year); | |
} else if (is_author()) { | |
$author = get_query_var('author'); | |
$canonical = get_author_posts_url($author); | |
} else if (is_category()) { | |
$cat = get_query_var('cat'); | |
$canonical = get_category_link($cat); | |
} else if (is_tag()) { | |
$tag = get_query_var('tag_id'); | |
$canonical = get_tag_link($tag); | |
} | |
echo '<link rel="canonical" href="' . $canonical . '" />'; | |
} | |
add_action('wp_head', 'seo_canonical'); | |
/* ---------- SOCIAL LINKS / SITE HEADER FIELDS ---------- */ | |
function custom_settings_api_init() { | |
add_settings_section('siteSettings','Global Styles','site_settings','general'); | |
add_settings_field('mastheadControl','Site Header Title','masthead_set','general','siteSettings'); | |
register_setting('general','mastheadControl'); | |
add_settings_field('mastheadControl_alt','Site Header Title Prefix','masthead_alt','general','siteSettings'); | |
register_setting('general','mastheadControl_alt'); | |
add_settings_field('mastheadControl_desc','Site Header Title Description','masthead_desc','general','siteSettings'); | |
register_setting('general','mastheadControl_desc'); | |
add_settings_section('socialSettings','Social Links','social_settings','general'); | |
add_settings_field('facebookControl','Facebook','set_facebook','general','socialSettings'); | |
register_setting('general','facebookControl'); | |
add_settings_field('twitterControl','Twitter','set_twitter','general','socialSettings'); | |
register_setting('general','twitterControl'); | |
add_settings_field('instagramControl','Instagram','set_instagram','general','socialSettings'); | |
register_setting('general','instagramControl'); | |
add_settings_field('pinterestControl','pInterest','set_pinterest','general','socialSettings'); | |
register_setting('general','pinterestControl'); | |
add_settings_field('googlepControl','Google+','set_googlep','general','socialSettings'); | |
register_setting('general','googlepControl'); | |
} | |
add_action('admin_init', 'custom_settings_api_init'); | |
function site_settings() {echo '<p>Specify text and image which are displayed on top of the site.</p>';} | |
function masthead_set() {echo '<input name="mastheadControl" id="mastheadControl" type="text" value="'. get_option('mastheadControl') .'" />';} | |
function masthead_alt() {echo '<input name="mastheadControl_alt" id="mastheadControl_alt" type="text" value="'. get_option('mastheadControl_alt') .'" />';} | |
function masthead_desc() {echo '<input name="mastheadControl_desc" id="mastheadControl_desc" type="text" value="'. get_option('mastheadControl_desc') .'" />';} | |
function social_settings() {echo '<p>Enter the URL to your social network profile and it will be displayed on the homepage.</p>';} | |
function set_facebook() {echo '<input name="facebookControl" id="facebookControl" type="text" value="'. get_option('facebookControl') .'" />';} | |
function set_twitter() {echo '<input name="twitterControl" id="twitterControl" type="text" value="'. get_option('twitterControl') .'" />';} | |
function set_instagram() {echo '<input name="instagramControl" id="instagramControl" type="text" value="'. get_option('instagramControl') .'" />';} | |
function set_pinterest() {echo '<input name="pinterestControl" id="pinterestControl" type="text" value="'. get_option('pinterestControl') .'" />';} | |
function set_googlep() {echo '<input name="googlepControl" id="googlepControl" type="text" value="'. get_option('googlepControl') .'" />';} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html <?php language_attributes(); ?>> | |
<head> | |
<meta charset="<?php bloginfo( 'charset' ); ?>" /> | |
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width"> | |
<meta name="apple-touch-fullscreen" content="yes"> | |
<meta name="apple-mobile-web-app-capable" content="yes"> | |
<link rel="shortcut icon" href="<?php echo get_template_directory_uri(); ?>/img/favicon.ico" type="image/x-icon" /> | |
<link rel="apple-touch-icon-precomposed" href="<?php echo get_template_directory_uri(); ?>/img/apple-retina.png" sizes="114x114" /> | |
<link rel="apple-touch-icon-precomposed" href="<?php echo get_template_directory_uri(); ?>/img/apple-ipad.png" sizes="72x72" /> | |
<link rel="apple-touch-icon" href="<?php echo get_template_directory_uri(); ?>/img/apple-touch.png" /> | |
<link rel="profile" href="http://gmpg.org/xfn/11" /> | |
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" /> | |
<?php if ( is_singular() && get_option( 'thread_comments' ) ) wp_enqueue_script( 'comment-reply' ); | |
wp_head();?> | |
</head> | |
<body <?php body_class(); ?> itemscope itemtype="http://schema.org/WebPage"> | |
<header class="site-header" role="banner" itemscope itemtype="http://schema.org/WPHeader"> | |
<div class="wrap"> | |
<hgroup class="title-area"> | |
<h1 class="site-title" itemprop="headline">Site Name</h1> | |
<h2 class="site-description" itemprop="description">Site Description</h2> | |
</hgroup> | |
</div> | |
</header><!-- /site-header --> | |
<nav class="nav-primary" role="navigation" itemscope itemtype="http://schema.org/WebPageElement http://schema.org/ItemList"> | |
<ul itemprop="name" content="navigation_menu"> | |
<li class="menu-1" itemprop="additionalType" itemscope itemtype="http://www.schema.org/SiteNavigationElement http://schema.org/itemListElement"><a href="/" title="Home" itemprop="url"></a></li> | |
<li class="menu-2" itemprop="additionalType" itemscope itemtype="http://www.schema.org/SiteNavigationElement http://schema.org/itemListElement"><a href="/about.php" title="About" itemprop="url"></a></li> | |
</ul> | |
</nav><!--/site-navigation --> | |
<section> | |
<main role="main" itemscope itemprop="mainContentOfPage" itemtype="http://schema.org/Blog"> | |
<article id="<?php get_the_ID(); ?> " itemscope itemprop="blogPost" itemtype="http://schema.org/BlogPosting"> | |
<header> | |
<h1 itemprop="headline"><a href="http://mysite.com/post" title="Blog Post" rel="bookmark">Blog Post</a></h1> | |
<time itemprop="datePublished" datetime="2012-01-07T07:07:21+00:00">January 7, 2012</time> | |
<span class="entry-author" itemprop="author" itemscope itemptype="http://schema.org/Person"> | |
<a href="http://mysite.com/author" class="entry-author-link" itemprop="url" rel="author"> | |
<span class="entry-author-name" itemprop="name">Author Name</span> | |
</a> | |
</span> | |
</header> | |
<div class="entry-content" itemprop="text"> | |
<p>This is a blog post.</p> | |
</div> | |
<footer class="entry-footer"> | |
<span class="cats">Filed Under: <a href="http://mysite.com/the-category" title="View all posts in Category" rel="category">The Category</a></span> | |
<span class="tags">Tagged With: <a href="http://mysite.com/?tag=tag-1" rel="tag">tag 1</a>, <a href="http://mysite.com/?tag=tag-2" rel="tag">tag 2</a></span> | |
</footer> | |
</article><!-- /post --> | |
<div class="entry-comments" id="comments"> | |
<h3>Comments</h3> | |
<ol> | |
<li class="comment" id="<?php comment_ID(); ?>"> | |
<article itemprop="comment" itemscope itemtype="http://schema.org/UserComments"> | |
<header itemprop="creator" itemscope itemtype="http://schema.org/Person"> | |
<span itemprop="name"><a href="http://authorswebsite.com" rel="external nofollow" itemprop="url">Comment Author</a></span> | |
<time itemprop="commentTime" datetime="2013-09-15T13:22:51+00:00">Sept. 15, 2013</time> | |
</header> | |
<p itemprop="commentText">some comment text etc etc...</p> | |
</article> | |
</li> | |
</ol> | |
</div><!-- /comments --> | |
<ul class="pagination" role="navigation" itemscope itemtype="http://schema.org/SiteNavigationElement"> | |
<li class="active" itemprop="name"><a class="more" href="/" itemprop="url">1</a></li> | |
<li itemprop="name"><a rel="next" class="more" href="" itemprop="url">2</a></li> | |
<li itemprop="name"><a class="more" href="" itemprop="url">3</a></li> | |
<li itemprop="name"><a class="more next" href="" itemprop="url">Next ></a></li> | |
</ul> | |
</main><!-- /content --> | |
<aside class="widgets" role="complementary" itemscope itemtype="http://schema.org/WPSideBar"> | |
<div class="widget"> | |
<h4>Primary Sidebar Widget</h4> | |
<p>This is the Primary Sidebar Widget</p> | |
</div> | |
</aside><!-- /site-sidebar --> | |
</section><!-- /section --> | |
<footer role="contentinfo" itemscope itemtype="http://schema.org/WPFooter"> | |
<div class="copyright" role="contentinfo" itemscope itemtype="http://schema.org/WPFooter"> | |
<a title="Back to top" href="#">Back to top</a> | |
<span itemprop="description">Slogan.</span> | |
<a href="#" alt="Title" target="_blank" rel="home"></a> is owned and operated by <a href="#" alt="Company" target="_blank" rel="home" itemprop="copyrightHolder">Company</a>, 2012-<?php echo date("Y") ?></p> | |
</div> | |
</footer><!-- /site-footer --> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment