WordPress: useful additions to functions.php

/*
* Useful snippets for functions.php
/*

/*
* Add support for the following:
*/
add_theme_support( ‘title-tag’ );
add_theme_support( ‘post-thumbnails’ );
add_theme_support( ‘html5’, array( ‘search-form’, ‘comment-form’, ‘comment-list’ ) );

/*
* Register Menus
*/
function register_my_menus(){
register_nav_menus(
array( ‘primary’ => __(‘Primary Menu’, ‘AD’), ) );
}
add_action(‘init’, ‘register_my_menus’);

/*
* Allow php in widget
*/
function howman_php_execute( $html ) {
if ( strpos($html,”<“.”?php”) !==false ) {
ob_start();
eval(“?”.”>”.$html);
$html=ob_get_contents();
ob_end_clean();
}
return $html;
}
add_filter(‘widget_text’,’howman_php_execute’, 100);

/*
*Enqueue Datepicker + jQuery UI CSS
*/
wp_enqueue_script( ‘jquery-ui-datepicker’ );
wp_enqueue_style( ‘jquery-ui-style’, ‘//ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/smoothness/jquery-ui.css’, true);

/*
* Add widgets
*/
function bootstrapstarter_widgets_init() {

register_sidebar( array(
‘name’ => ‘Footer – Copyright Text’,
‘id’ => ‘footer-copyright-text’,
‘before_widget’ => ‘<div class=”footer_copyright_text”>’,
‘after_widget’ => ‘</div>’,
‘before_title’ => ‘<h4>’,
‘after_title’ => ‘</h4>’,
) );

register_sidebar( array(
‘name’ => ‘Sidebar – Inset’,
‘id’ => ‘sidebar-1’,
‘before_widget’ => ‘<div class=”sidebar-module sidebar-module-inset”>’,
‘after_widget’ => ‘</div>’,
‘before_title’ => ‘<h4>’,
‘after_title’ => ‘</h4>’,
) );

register_sidebar( array(
‘name’ => ‘Sidebar – Default’,
‘id’ => ‘sidebar-2’,
‘before_widget’ => ‘<div class=”sidebar-module”>’,
‘after_widget’ => ‘</div>’,
‘before_title’ => ‘<h4>’,
‘after_title’ => ‘</h4>’,
) );

}
add_action( ‘widgets_init’, ‘bootstrapstarter_widgets_init’ );

/*
* Register jQuery
*/
if (!is_admin()) {
wp_deregister_script(‘jquery’);
wp_register_script(‘jquery’, (“https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js”), false);
wp_enqueue_script(‘jquery’);
}

/*
* Custom Excerpt Length
*/
function custom_excerpt_length($length) {
return 25;
}
add_filter(‘excerpt_length’, ‘custom_excerpt_length’);

/*
* Add scripts, stylesheets, fonts, etc.
*/
function mysite_enqueue_styles() {
wp_register_style(‘bootstrap’, get_template_directory_uri() . ‘/bootstrap/css/bootstrap.min.css’ );
$dependencies = array(‘bootstrap’);
wp_enqueue_style( ‘mysite-style’, get_stylesheet_uri(), $dependencies );
}
add_action( ‘wp_enqueue_scripts’, ‘mysite_enqueue_styles’ );

function startwordpress_scripts() {
wp_enqueue_script( ‘bootstrap’, get_template_directory_uri() . ‘/js/bootstrap.min.js’, array( ‘jquery’ ), ‘3.3.6’, true );
wp_enqueue_script( ‘validator’, get_template_directory_uri() . ‘/js/jquery.validate.min.js’, array ( ‘jquery’ ), ‘3.3.6’, true);
}
add_action( ‘wp_enqueue_scripts’, ‘startwordpress_scripts’ );

function startwordpress_google_fonts() {
wp_register_style(‘Lato’, ‘http://fonts.googleapis.com/css?family=Lato:100,200,400,600,700,800’);
wp_enqueue_style( ‘Lato’);
wp_register_style(‘Nunito’, ‘https://fonts.googleapis.com/css?family=Nunito+Sans” rel=”stylesheet”>’);
wp_enqueue_style( ‘Nunito’);
// wp_register_style(‘OpenSans’, ‘https://fonts.googleapis.com/css?family=Open+Sans” rel=”stylesheet”>’);
// wp_enqueue_style( ‘OpenSans’);
}
add_action(‘wp_print_styles’, ‘startwordpress_google_fonts’);


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>