Skip to content

Instantly share code, notes, and snippets.

@igorbenic
Last active September 17, 2017 22:55
Show Gist options
  • Select an option

  • Save igorbenic/89f6a7583e3fe0c7f36d3905efacd5ee to your computer and use it in GitHub Desktop.

Select an option

Save igorbenic/89f6a7583e3fe0c7f36d3905efacd5ee to your computer and use it in GitHub Desktop.
The Beginner's Guide to WordPress Theme Development | http://www.ibenic.com/beginners-guide-wordpress-theme-development
<?php
add_action( 'wp_enqueue_scripts', 'child_theme_styles' );
function child_theme_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
<?php
if ( is_active_sidebar( 'main-sidebar' ) ) : ?>
<ul id="sidebar">
<?php dynamic_sidebar( 'main-sidebar' ); ?>
</ul>
<?php endif; ?>
<?php
add_action( 'wp_enqueue_scripts', 'enqueue' );
function enqueue() {
wp_enqueue_style( 'style', get_stylesheet_uri() );
// Example of another CSS: inside the theme folder /css/ without any dependencies (false), version: 1.1 and for all media
wp_enqueue_style( 'style-css-2', get_template_directory_uri() . '/css/style-2.css', false, '1.1', 'all' );
// Enqueueing Script inside the theme folder /js/ with jQuery dependency. Version 1.1 and enqueued in the footer (true)
wp_enqueue_script( 'script', get_template_directory_uri() . '/js/script.js', array ( 'jquery' ), 1.1, true);
}
<?php
function my_theme_function() {
register_nav_menus( array(
'primary' => __( 'Primary Menu', 'myfirsttheme' ),
'secondary' => __('Secondary Menu', 'myfirsttheme' )
));
}
add_action( 'after_setup_theme', 'my_theme_function' );
<?php
get_sidebar( 'main' );
<?php
if( have_posts() ) {
while( have_posts() ) {
the_post(); // set the next post in the loop as the current post
//Display the Title
the_title();
}
}
<?php
add_action( 'widgets_init', 'theme_widget' );
function theme_widget() {
register_sidebar( array(
'name' => __( 'Main Sidebar', 'yourtextdomain' ),
'id' => 'main-sidebar',
'description' => __( 'Sidebar Description', 'yourtextdomain' ),
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
));
}
/*
Theme Name: Your Theme Child
Theme URI: https://your.theme.url
Template: yourthemename
...
*/
/*
Theme Name: Your Theme Name
Theme URI: https://your.theme.url
Author: Theme Author
Author URI: Authour URL
Description: Theme Description
Version: 1.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: yourtextdomain
Tags: blue, white, responsive
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment