Skip to content

Instantly share code, notes, and snippets.

@bewho
bewho / wp-fa-menu-anchor-icons.php
Created January 16, 2018 01:20 — forked from renventura/wp-fa-menu-anchor-icons.php
Add Font Awesome icons to WordPress menu anchor text
<?php //* Mind this opening PHP tag
/**
* Append Font Awesome icons to menu-item anchor text
* Requires the "fa" and "fa-{icon_key}" classes to be added to the menu item
*
* @author Ren Ventura <EngageWP.com>
* @link http://www.engagewp.com/add-font-awesome-icons-to-wordpress-menu-anchor-text/
*
* @param $item Menu-item object
@bewho
bewho / header.php
Created January 16, 2018 09:02 — forked from Shumaher/header.php
Open Graph tags for WordPress, see http://blog.alexz.me/wp-opengraph for more info
<head>
<?php if (is_single() || is_page()) { ?>
<meta name="description" content="<?php $s = trim(str_replace("\r\n", " ", htmlspecialchars(strip_tags($post->post_content)))); if(mb_strlen($s,'UTF-8') > 200){$postdescr = mb_substr($s,0,198,'UTF-8').' …';} else{$postdescr = $s;}; echo $postdescr; ?>" />
<meta property="og:description" content="<?php echo $postdescr; ?>" />
<meta property="og:url" content="http://site.com/<?php global $post; echo $post->post_name; ?>" /> <!-- OR -->
<meta property="og:url" content="<?php the_permalink() ?>" />
<meta property="og:title" content="Site Name<?php wp_title(); ?>" />
<meta property="og:headline" content="Site Name<?php wp_title(); ?>" />
<?php if (get_post_meta($post->ID, 'image_id', true)){$postimage = wp_get_attachment_image_src(get_post_meta($post->ID, 'image_id', true), 'full'); ?>
<link rel="image_src" href="<?php echo $postimage[0]; ?>" />
@bewho
bewho / wordpress-functionality-plugin.php
Created January 21, 2018 00:18 — forked from rickrduncan/wordpress-functionality-plugin.php
This WordPress functionality plugin contains code snippets that tweak WordPress core and do not contain theme specific functionality. This is code that I run on every single website I build using WordPress.
<?php
/**
* Plugin Name: WordPress Functionality Plugin
* Plugin URI: http://rickrduncan.com/wordpress/functionality-plugin
* Description: Core WordPress customizations that are theme independent.
* Author: Rick R. Duncan - B3Marketing, LLC
* Author URI: http://rickrduncan.com
*
*
* Version: 1.0.0
@bewho
bewho / quote-author.php
Created January 21, 2018 00:19 — forked from thefuxia/quote-author.php
WordPress Plugin Quote Author
<?php # -*- coding: utf-8 -*-
/*
Plugin Name: Custom Taxonomy Quote Author
Plugin URI: https://gist.github.com/996608
Description: Creates a custom taxonomy <code>Quote Author</code> with an URI <code>/qa/author-name/</code>
Version: 1.0
Required: 3.1
Author: Thomas Scholz
Author URI: http://toscho.de
License: GPL
@bewho
bewho / index.html
Created January 23, 2018 01:44 — forked from hsquareweb/index.html
Collapsable/Toggle Links
<ul class="collapse_list">
<li><a href="#" data-toggle="collapse" data-target="#one">One</a></li>
<li><a href="#" data-toggle="collapse" data-target="#two">Two</a></li>
</ul>
<div class="collapse_content">
<div id="one">
<p>Content for div one</p>
</div>
@bewho
bewho / paste-as-plain-text.php
Created January 23, 2018 02:29 — forked from tillkruss/paste-as-plain-text.php
Force the WordPress editor to always paste as plain text.
<?php
// always paste as plain text
foreach ( array( 'tiny_mce_before_init', 'teeny_mce_before_init') as $filter ) {
add_filter( $filter, function( $mceInit ) {
$mceInit[ 'paste_text_sticky' ] = true;
$mceInit[ 'paste_text_sticky_default' ] = true;
return $mceInit;
});
}
@bewho
bewho / functions.php
Created January 23, 2018 13:56 — forked from MikeNGarrett/functions.php
Set cache headers on WordPress 404 pages.
<?php
/**
* Force cache headers on 404 pages and prevent WordPress from handling 404s.
*
* @param bool $preempt determines who handles 404s.
* @param obj $wp_query global query object.
*/
function change_404_headers( $preempt, $wp_query ) {
if ( ! is_admin() && ! is_robots() && count( $wp_query->posts ) < 1 ) {
header( 'Cache-Control: max-age=30000, must-revalidate' );
@bewho
bewho / wp-config.php
Created January 23, 2018 14:02 — forked from MikeNGarrett/wp-config.php
Disable admin-ajax on the front-end of WordPress sites and cache the resulting 404.
<?php
if(
strpos( $_SERVER['HTTP_REFERER'], 'wp-admin' ) === false &&
strpos( $_SERVER['REQUEST_URI'], 'admin-ajax.php' ) !== false
) {
header( 'Cache-Control: max-age=30000, must-revalidate' );
header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', strtotime( '+5000 minutes' ) ) . ' GMT' );
header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', strtotime( '-5000 minutes' ) ) . ' GMT' );
header( $_SERVER["SERVER_PROTOCOL"]." 404 Not Found" );
die;
@bewho
bewho / wp_functions.php
Created January 25, 2018 16:15 — forked from Kobe/wp_functions.php
deactivate anything in wp_head
<?php
// add theme support for
add_theme_support('html5');
add_theme_support('menus');
add_theme_support('post-formats', array(
'aside',
'image',
'link',
'status'
));
########################################################################################
# bewho's robots.txt file for RadarTek websites
########################################################################################
User-agent: *
Allow: /
Allow: /robots.txt
Allow: /*.png*
Allow: /*.jpg*
Allow: /*.jpeg*