Skip to content

Instantly share code, notes, and snippets.

@jpen365
jpen365 / add-wp_head-and-wp_footer-to-index.php
Last active July 9, 2019 17:50
An example of where the wp_head and wp_footer hooks must be added to index.php
@jpen365
jpen365 / file-header.php
Created September 14, 2016 04:11
An example of a file header for a header.php theme template partial
<?php
/**
* The header for our theme.
*
* Displays all of the <head> section and everything up till <div id="content">
*
* @package Simple Blog Theme
*/
?>
@jpen365
jpen365 / get_header-example.php
Last active July 9, 2019 17:50
Example of how get_header() is added to a WordPress template file.
<?php
/**
* The main template file
* It puts together the home page if no home.php file exists.
*
* @package Simple Blog Theme
*/
get_header(); ?>
<!-- the beginning of the page or post content -->
@jpen365
jpen365 / add-menu-area-to-functions.php
Created September 14, 2016 18:04
Add the primary menu area to functions.php
/* add theme menu area */
register_nav_menus (array(
'primary' => 'Primary Menu',
));
@jpen365
jpen365 / add-nav-menu-to-header.php
Created September 14, 2016 18:07
Add a menu to header.php with wp_nav_menu
<?php
wp_nav_menu( array(
'theme_location' => 'primary',
'menu_class' => 'nav navbar-nav',
'container_id' => 'bs-example-navbar-collapse-1',
'container_class' => 'collapse navbar-collapse',
));
?>
@jpen365
jpen365 / basic-loop.php
Created September 14, 2016 19:17
The WordPress Loop at its most basic
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
/* insert post content here */
<?php endwhile; else : ?>
<p><?php _e( 'Sorry, there doesn\'t appear to be anything here.' ); ?></p>
<?php endif; ?>
@jpen365
jpen365 / a-simpe-loop.php
Last active September 16, 2016 01:25
A simple loop
<?php
// Note: this loop is a simplified version of a loop published in a post at Elegant Themes
// Source: https://www.elegantthemes.com/blog/tips-tricks/converting-html-sites-to-wordpress-sites
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="post-header">
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p>By <?php the_author_posts_link(); ?>, <?php the_time( 'M j y' ); ?></p>
</header>
<div class="entry clear">
@jpen365
jpen365 / Register-sidebar.php
Last active July 9, 2019 17:49
Function that registers my theme's sidebar area
<?php
/* register widget areas */
function jpen_sidebar_widget_area() {
register_sidebar( array(
'name' => 'Sidebar Widget Area',
'id' => 'jpen-sidebar-widgets',
'before_widget' => '<div class="well">',
'after_widget' => '</div>',
'before_title' => '<h4>',
'after_title' => '</h4>',
@jpen365
jpen365 / add-widget-area-to-sidebar.php
Created September 14, 2016 22:22
Add widget area to sidebar
<div class="col-md-4">
<?php dynamic_sidebar( 'jpen-sidebar-widgets' ); ?>
</div>
<?php
/**
* The main template file
* It puts together the home page if no home.php file exists.
*
* @package Simple Blog Theme
*/
get_header(); ?>
<!-- all page or post content should be between the header and sidebar -->