Skip to content

Instantly share code, notes, and snippets.

@bryanwillis
bryanwillis / freshcustomcode.php
Last active January 13, 2016 22:29
Custom wordpress admin toolbar #adminbar #toobar #wpadmin
<?php
function fresh_custom_admin_bar_init() {
if ( is_admin() || !is_admin_bar_showing() )
return;
add_action('admin_bar_menu', 'fresh_custom_admin_bar_links', 500);
}
add_action('admin_bar_init', 'fresh_custom_admin_bar_init');
@bryanwillis
bryanwillis / get_all_post_type_metaboxes.php
Last active November 2, 2015 05:58
Use this on: http://example.com/wp-admin/post.php. It will print a function at the top of the screen for all the metaboxes registered to that post type.
<?php
function get_current_post_type() {
global $post, $typenow, $current_screen;
if ($post && $post->post_type)
return $post->post_type;
elseif ($typenow)
return $typenow;
elseif ($current_screen && $current_screen->post_type)
return $current_screen->post_type;
elseif (isset($_REQUEST['post_type']))
@bryanwillis
bryanwillis / nav-menu-shortcodes.php
Last active August 29, 2015 14:04
Add shortcodes and html to description field to override menu
<?php
/**
* Nav Menu Shortcodes
*
* @package Nav Menu Shortcodes
* @author Bryan Willis <[email protected]>
* @license GPL-2.0+
* @link http://www.canddibusiness.com
*
* @wordpress-plugin
@robneu
robneu / genesis-header-right-div.php
Last active January 8, 2016 23:29
By default, the Genesis header-right widget area uses an <aside> element. While this is fine most of the time, if you're using the header-right section for your primary navigation it is probably less than ideal for it to be wrapped in an <aside>. This will change the <aside> to a standard <div> element.
<?php
add_filter( 'genesis_markup_header-widget-area_output', 'prefix_opening_header_div', 10, 2 );
/**
* Replace the opening header-right <aside> tag with a <div> tag to allow the
* primary nav to be used in the header without being wrapped in an aside tag.
*
* @param $tag string The current tag for the .header-right widget area.
* @param $args array The current args for genesis_attr()
* @return $tag string The modified tag for the .header-right widget area.
RewriteRule ^dashboard/(.*) wp-admin/$1?%{QUERY_STRING} [L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
@bryanwillis
bryanwillis / delete-missing-images.php
Last active September 6, 2020 11:39
delete image references to the wordpress database when they have been deleted from from the uploads folder and not from the admin interface
<?php
// Only run the code if we are in the admin
if ( is_admin() ) :
class WordPressdeleteMissingImages {
// Action/Filter Hooks
function __construct() {
add_action( 'admin_menu', array( &$this, 'add_page' ) );
@bryanwillis
bryanwillis / current-url.php
Last active January 9, 2016 19:26
Some examples using PHP url parameters functions like parsing the URL and getting the current URL for Wordpress useage. Also example using unparse_url() in javascript.
<?php
/**
* Gets the URL of current page or requested page
*/
function bw_get_url($url) {
if ($_SERVER['REQUEST_URI'] == '') {
$url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REDIRECT_URL'];
} else {
$url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
}
//uses single template but not as good for theme compatability
<?php
function custom_template_snippet_post_type_plugin( $single ) {
global $wp_query, $post;
if ($post->post_type == "sdr_snippet"){
// if in subfolder
$template = plugin_dir_path( __FILE__ ) . 'templates/single-snippet.php';
// if in plugin root directory folder
//$template = plugin_dir_path( __FILE__ ) . '/single-snippet.php';
@robincornett
robincornett / functions.php
Last active April 12, 2022 07:36
optional home.php--to show the posts (blog) page's title and content
<?php
// do NOT include the opening line! Just add what's below to the end of your functions.php file
add_action( 'edit_form_after_title', 'rgc_posts_page_edit_form' );
function rgc_posts_page_edit_form( $post ) {
$posts_page = (int) get_option( 'page_for_posts' );
if ( $posts_page === $post->ID ) {
add_post_type_support( 'page', 'editor' );
}
@bryanwillis
bryanwillis / calc-attribute.css
Last active August 29, 2015 14:10
Complicated CSS selectors, rules, tricks, etc...
#formbox {
width: 130px; /* fallback for browsers without support for calc() */
width: calc(100% / 6);
border: 1px solid black;
padding: 4px;
}
input {
padding: 2px;
display: block;
width: 98%; /* fallback for browsers without support for calc() */