WordPress – How to override javascript files in a child theme?

How to override javascript files in a child theme?

Add to your functions.php  file the following code:

<?php
 // hook in late to make sure the parent theme's registration
 // has fired so you can undo it. Otherwise the parent will simply
 // enqueue its script anyway.
 add_action('wp_enqueue_scripts', 'wpse26822_script_fix', 100);
 function wpse26822_script_fix()
 {   wp_dequeue_script('parent_theme_script_handle');
     wp_enqueue_script('child_theme_script_handle',
        get_stylesheet_directory_uri().'/scripts/yourjs.js', array('jquery'));
 }
 ?>

Resource:
http://wordpress.stackexchange.com/questions/26822/how-to-override-javascript-files-in-child-theme



WordPress – Create an Options Page for a Theme

How to create an options page for your WordPress theme?

Add the following code to your functions.php file.

First add an item to the admin menu:

function my_admin_menu()
{  if (function_exists('add_options_page'))
   { add_options_page(__('My theme settings','twentyfourteen'), __('My theme settings','twentyfourteen'), 'manage_options', 'my_admin', 'my_options_page');
   }
} // my_admin_menu()
add_action( 'admin_menu', 'my_admin_menu' );

Then add the code for the options page:

function my_options_page()
{
    global $wpdb;

    if (isset($_POST['action']) && $_POST['action']=='save_options')
    {    // SAVE OPTIONS
        update_option('ibs_facebook_url', $_REQUEST['facebook_url']);
        echo "<div class='updated'><p><strong>".__('My Theme Settings UPDATED!','twentyfourteen')."</strong></p></div>";
    }
    
    $facebook_url = get_option('ibs_facebook_url');
    if(!$facebook_url) $facebook_url = '#';
?>
<br />
<h1><?php echo __('My Theme Settings', 'twentyfourteen'); ?></h1>
<br />
<form action="" method="post" name="options_form">
  <input name="action" type="hidden" value="save_options" />
  <table border="0" cellspacing="0" cellpadding="5">
    <tr>
      <td>Facebook URL</td>
      <td><input type="text" name="facebook_url" id="facebook_url" value="<?php echo $facebook_url;?>" size="60" /></td>
    </tr>       
    <tr>
      <td colspan="2"><br />
        <input name="submit" type="submit" value="<?php echo __('SAVE OPTIONS', 'twentyfourteen'); ?>" class="button-primary button-large" /></td>
    </tr>
  </table>
</form>
<?php
} // my_options_page()

WordPress – Add a Javascript File to your Theme

How to add a theme-specific javascript file to your (child-)theme?

Put the javascript file in your theme folder (in this example: theme.js).

Add the following code to your functions.php file:

/**
 * Load a theme specific javascript file
 */
function load_theme_js()
{
    // A trick to get the child theme directory...
    $child_theme_url = get_stylesheet_uri();
    $child_theme_url = str_replace('/style.css', '', $child_theme_url);
    $output = '<script type="text/javascript" src="'.$child_theme_url.'/theme.js"></script>';
    echo $output;
}
add_action('wp_head','load_theme_js');
?>

This will put a link to your javascript file in the header of each page!


WordPress – Create a Child Theme

How to create a WordPress Child Theme?

Create a new folder:
/wp-content/themes/my-child

Create a new file called style.css in the new folder:

/*
 Theme Name: my-child
 Theme URI: http://the-theme's-homepage
 Description: a-brief-description
 Author: your-name
 Author URI: your-URI
 Template: twentyeleven
 Version: a-number--optional
 .
 General comments/License Statement if any.
 .
 */
 @import url(../twentyeleven/style.css);

Put a screenshot.png file in the new folder.
Override any theme file you want, like index.php, page.php, etc.

Pay attention!
The functions.php file will be added, not overridden!
So, just create a functions.php file with additions and functions you want to override, don’t make a copy of the whole orginal file!

Pay attention!
Don’t forget to switch the theme to the new child theme!

Resources:
http://codex.wordpress.org/Child_Themes
http://www.ostraining.com/blog/wordpress/child-theme/


WordPress – Sort Posts on Modified Date

How to sort posts on modified date (instead of creation date)?

Edit the functions.php file (in your theme)

function twentyeleven_posted_on() {
    printf( __( 'Modified on   by  ', 'twentyeleven' ),
        esc_url( get_permalink() ),
        esc_attr( get_the_modified_time() ),
        esc_attr( get_the_modified_date( 'c' ) ),
        esc_html( get_the_modified_date() ),
        esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
        sprintf( esc_attr__( 'View all posts by %s', 'twentyeleven' ), get_the_author() ),
        esc_html( get_the_author() )
    );
}

For the twentyfourteen theme (create a functions.php file):

if ( ! function_exists( 'twentyfourteen_posted_on' ) ) :
/**
 * Print HTML with meta information for the current post-date/time and author.
 *
 * @since Twenty Fourteen 1.0
 */
function twentyfourteen_posted_on() {
    if ( is_sticky() && is_home() && ! is_paged() ) {
        echo '<span class="featured-post">' . __( 'Sticky', 'twentyfourteen' ) . '</span>';
    }

    // Set up and print post meta information.
    printf( '<span class="entry-date"><a href="%1$s" rel="bookmark"><time class="entry-date" datetime="%2$s">%3$s</time></a></span>',
        esc_url( get_permalink() ),
        esc_attr( get_the_modified_date( 'c' ) ),
        esc_html( get_the_modified_date() )
    );
}
endif;

Edit index.php (in your theme):

if ( have_posts() ) :
    // Start the Loop.
    # RvG
    global $query_string;
    query_posts($query_string . '&orderby=modified&order=desc');    
    while ( have_posts() ) : the_post();

Resources:
http://wordpress.org/support/topic/sorting-posts-by-modified-date-not-creation-date