Skip to content

Instantly share code, notes, and snippets.

View priscillamc's full-sized avatar

Priscilla Chapman priscillamc

View GitHub Profile
@priscillamc
priscillamc / wp-add-inline-scripts.md
Last active October 4, 2019 14:53
Adding inline javascript in WordPress 4.5+ using wp_add_inline_script()

Adding Inline Scripts in WordPress

Since WordPress 4.5, you can add the inline JavaScript using the wp_add_inline_script() function. This can be used instead of echoing inline scripts using wp_footer. The first argument is the handle of a registered script, in this case 'pretty-photo'.

function add_styles_scripts(){
	// Add script in the footer
	wp_enqueue_script('pretty-photo', get_stylesheet_directory_uri() . '/.../jquery.prettyPhoto.js', 
		array('jquery'), NULL, true);
	

Display Featured Image, if exists (in loop)

if ( has_post_thumbnail() ){
    the_post_thumbnail();
}

Display theme image

<img src="<?php echo get_styleshet_directory_uri(); ?>/images/logo.png" class="" alt="" />
/**
* Add styles and scripts to a WordPress site
*
* See https://codex.wordpress.org/Class_Reference/WP_Styles#Conditional_Styles
*/
function my_scripts_styles(){
global $wp_styles;
// Load IE version-specific stylesheets
wp_enqueue_style( 'html5shiv', 'https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js', array(), '3.7.2', 'screen' );
# Bootstrap
* http://bootswatch.com/
* https://wrapbootstrap.com/
# WordPress
* https://github.com/zamoose/themehookalliance
* https://wordpress.org/plugins/tha-hooks-interface/
<!-- Simple Calendar 3.0.4 - UF Template -->
<div class="event item">
<div class="eventdate event-date">
<div class="month">[start-date format="M"]</div>
<div class="day">[start-date format="j"]</div>
</div>
<div class="eventtitle">
<h4>[link][title][/link]</h4>
[if-whole-day]<div class="time">All Day</div>[/if-whole-day]
[if-not-whole-day]<div class="time">[start-date format="g:i A"] - [end-date format="g:i A"]</div>[/if-not-whole-day]
@priscillamc
priscillamc / wp-hide-customizer-admin-links
Created August 13, 2015 21:13
Remove WordPress Customizer links from the Admin Toolbar and dashboard by changing the body class back to 'no-customize-support'. This is a way to show only the original admin toolbar links for themes that don't support the Customizer.
<?php
/*
Plugin Name: Auto Update
Description: Enables automatic background updates for core, plugins, and themes. See <a href="https://codex.wordpress.org/Configuring_Automatic_Background_Updates" target="_blank">Configuring Automatic Background Updates</a> for more details.
Version: 1.0.0
*/
// Enable automatic updates for core major releases
add_filter( 'allow_major_auto_core_updates', '__return_true' );
<script type="text/javascript">
jQuery(function($){
// Your jQuery code here, using the $
});
</script>
@priscillamc
priscillamc / git-email-fix
Created April 15, 2015 13:33
Git fix email settings in branch
git config --global user.email
git config --global user.email "username@users.noreply.github.com"
git filter-branch --commit-filter '
if [ "$GIT_AUTHOR_EMAIL" = "email@example.com" ];
then
GIT_AUTHOR_NAME="username";
GIT_AUTHOR_EMAIL="username@users.noreply.github.com";
git commit-tree "$@";
// Use custom template pages in a WordPress plugin
function my_cpt_templates( $template_path ){
// Change template for CPT single pages
if( is_singular('my_cpt') ){
$template_path = plugin_dir_path( __FILE__ ) . 'templates/single-cpt.php';
}
// Change template for CPT archive pages for a certain taxonomy