Skip to content

Instantly share code, notes, and snippets.

View robertdevore's full-sized avatar
🐺
#LoneWolfLifestyle

Robert DeVore robertdevore

🐺
#LoneWolfLifestyle
View GitHub Profile
@robertdevore
robertdevore / functions.php
Last active August 29, 2015 14:26
WordPress: the_excerpt customizations
<?php
/**
* Changing the excerpt length
*
* the default length is 55 words and the code below changes it to 25 words
*/
function custom_excerpt_length( $length ) {
return 25;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
@robertdevore
robertdevore / contact-form-7-enhancement.php
Last active August 29, 2015 14:27
Only load Contact Form 7 scripts when the post/page uses the shortcode
<?php
/**
* Contact Form 7
* Speed enhancement
*
* The code below checks for the use of the CF7 shortcode and will remove scripts and styles when it isn't being used
*/
function deviodigital_deregister_contact_form() {
global $post;
if ( ! has_shortcode( $post->post_content, 'contact-form-7' ) ) {
@robertdevore
robertdevore / functions-custom-login-logo.php
Last active September 18, 2015 19:26
Let your theme's customizer logo upload option override the default WordPress login logo
<?php
/*
* Change the "mnml" text througout the code below to whatever you'd like to use
*
* Also, make sure the get_theme_mod instances are changed to your customizer option names
*
*/
// Add custom logo to login page if it's uploaded through the customizer
if ( get_theme_mod( 'mnml_logo' ) ) {
@robertdevore
robertdevore / plugin-update-notice.php
Created September 28, 2015 12:59
WordPress function to add a notice bar to the admin screen
<?php
function devio_functionname() {
if ( is_admin() && current_user_can( 'manage_options' ) ) {
echo '<div class="updated" id="message"><p>Put your notice here</p></div>';
}
}
add_action( 'admin_notices', 'devio_functionname' );
?>
@robertdevore
robertdevore / wordpress-shortcode-output-help.php
Created October 9, 2015 13:06
Stop the shortcode from displaying ABOVE all content in a post/page
<?php
/*
* This code stops your shortcode from displaying
* at the top of your WordPress page or post
*/
ob_start();
// Do stuff
@robertdevore
robertdevore / functions-featuredimage-rest-api.php
Created December 2, 2015 16:59
This function adds the full size featured image URL to the REST API output
<?php
function my_rest_prepare_post( $data, $post, $request ) {
$_data = $data->data;
$thumbnail_id = get_post_thumbnail_id( $post->ID );
$thumbnail = wp_get_attachment_image_src( $thumbnail_id, 'full' );
$_data['featured_image_thumbnail_url'] = $thumbnail[0];
$data->data = $_data;
return $data;
}
add_filter( 'rest_prepare_post', 'my_rest_prepare_post', 10, 3 );
@robertdevore
robertdevore / wp-api-call.js
Created December 4, 2015 15:39
jQuery code to display recent posts from the WordPress API
jQuery(document).ready(function($) {
$.get( "wp-json/wp/v2/posts", function( data ) {
$.each( data, function( i, val ) {
$( "#app" ).append(
'<li>' +
'<h3>' +
val.title.rendered +
'</h3>' +
'<p>' +
val.excerpt.rendered +
@robertdevore
robertdevore / wordpress-footer-menu-conditional.php
Last active December 4, 2015 17:37
WordPress footer menu conditional check
@robertdevore
robertdevore / wp-dispensary-api-example.html
Last active January 18, 2016 12:38
Quick and dirty API example for the WP Dispensary plugin
<html>
<head>
<title>WP Dispensary Example API Usage</title>
</head>
<body>
<script type="text/javascript" src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<ul id="app"></ul>
<script>
<?php
/**
* custom excerpt length for WordPress posts
* call the excerpt in your theme file with 'echo excerpt(25)'
* change the number to whatever amount of words you want to show
*/
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);