Skip to content

Instantly share code, notes, and snippets.

@andyknapp
andyknapp / functions.php
Created July 10, 2013 17:35
dynamic date function for wp
function copyright_date() {
global $wpdb;
$copyright_dates = $wpdb->get_results("
SELECT
YEAR(min(post_date_gmt)) AS firstdate,
YEAR(max(post_date_gmt)) AS lastdate
FROM
$wpdb->posts
WHERE
post_status = 'publish'
@andyknapp
andyknapp / index.html
Created July 10, 2013 14:42
A CodePen by Chris Coyier. Don't Overthink It Grids - Writeup on CSS-Tricks : http://css-tricks.com/dont-overthink-it-grids/
<h1>Don't Overthink It Grids <em>(while we wait for flexbox)</em></h1>
<div class="grid">
<div class="col-2-3">
<div class="module">
<h3>2/3</h3>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>
</div>
</div>
<div class="col-1-3">
@andyknapp
andyknapp / index.html
Created June 20, 2013 12:08
Sticky footer from CSS-Tricks
<div class="container">
<header></header>
<div class="content"></div>
</div>
<footer class="site-footer">
<p>footer stays at bottom</p>
</footer>
@andyknapp
andyknapp / functions.php
Created June 20, 2013 02:25
Default WP post thumbnail (featured img) if one isn't uploaded
function ak_post_thumbnail_html( $html ) {
if ( empty( $html ) )
$html = '<img src="' . trailingslashit( get_stylesheet_directory_uri() ) . 'images/default-thumbnail.jpg' . '" alt="No Image provided" />';
return $html;
}
add_filter( 'post_thumbnail_html', 'ak_post_thumbnail_html' );
@andyknapp
andyknapp / functions.php
Created June 20, 2013 02:19
Remove items from WP admin (profile section in this example) with jQuery Felt kinda weird to use js to do this, but had to be done and was the only solution I could come up with
function hide_personal_options(){echo "\n"
. '<script type="text/javascript">jQuery(document).ready(function($) {
$(\'form#your-profile > h3:first\').hide();
$(\'form#your-profile > table:first\').hide();
$(\'table.form-table:eq(1) tr:eq(3)\').hide();
$(\'table.form-table:eq(1) tr:eq(4)\').hide();
$(\'table.form-table:eq(2) tr:eq(1)\').hide();
$(\'table.form-table:eq(2) tr:eq(2)\').hide();
$(\'table.form-table:eq(2) tr:eq(3)\').hide();
$(\'table.form-table:eq(2) tr:eq(4)\').hide();
@andyknapp
andyknapp / functions.php
Created June 20, 2013 02:17
Remove / add from the WP admin bar I found this useful in a multisite install where I wanted network sites to link back to the main site homepage, as opposed to the individual network site homepage
function ak_admin_bar_nav($wp_toolbar) {
$wp_toolbar->remove_node('comments');
$wp_toolbar->remove_node('new-content');
$wp_toolbar->remove_node('my-sites');
$wp_toolbar->remove_node('wp-logo');
$wp_toolbar->add_node(array(
'id' => 'theid',
'title' => 'A Title',
'href' => 'http://linkurl.com'
));
@andyknapp
andyknapp / functions.php
Created June 20, 2013 02:13
WP admin tinyMCE customization
// top row
if(!function_exists('ak_editor_mce_buttons_top')) {
function ak_editor_mce_buttons_top($buttons) {
return array( 'bold', 'italic', 'strikethrough', 'separator', 'bullist', 'numlist', 'justifyleft', 'justifycenter', 'justifyright', 'spellchecker' );
/* wp defaults
return array(
'bold', 'italic', 'strikethrough', 'separator', 'bullist', 'numlist', 'blockquote', 'separator', 'justifyleft', 'justifycenter', 'justifyright', 'separator',
'link', 'unlink', 'wp_more', 'separator', 'spellchecker', 'fullscreen', 'wp_adv' );
*/
@andyknapp
andyknapp / functions.php
Last active December 18, 2015 17:39
Default text in WP wysiwyg editor
function ak_editor_content( $content ) {
$content.= "<p>This content is now default text in the wysiwyg editor.</p>";
$content.= "<p>And so is this";
return $content;
}
add_filter( 'default_content', 'ak_editor_content');
@andyknapp
andyknapp / functions.php
Created June 20, 2013 02:08
Remove meta boxes from WP write post screen
function ak_custom_meta_box_removal() {
remove_meta_box( 'postexcerpt', 'product', 'normal' );
remove_meta_box( 'authordiv', 'product', 'normal' );
remove_meta_box( 'revisionsdiv', 'product', 'normal' );
remove_meta_box( 'slugdiv', 'product', 'normal' );
remove_meta_box( 'mp-meta-download', 'product', 'normal');
}
add_action('admin_menu', 'ak_custom_meta_box_removal');
@andyknapp
andyknapp / functions.php
Created June 20, 2013 02:06
Add a page to the WP admin add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position ); ?>
add_action('admin_menu', 'ak_menu');
function ak_menu() {
add_menu_page('Page Title', 'Menu Title', 'administrator', 'new-pg', 'ak_menu_content');
}
function ak__menu_content(){ ?>
<div class="wrap">
<h2>Page Title</h2>
<p>content</p>
</div>