Skip to content

Instantly share code, notes, and snippets.

View 5A5K1A's full-sized avatar
🦄

Saskia Bouten 5A5K1A

🦄
View GitHub Profile
@5A5K1A
5A5K1A / wordpress-hooks-admin-save.php
Last active February 4, 2017 21:16
WordPress Make "in-site" URL's relative
<?php
/* ------------------------------------ */
/* Convert absolute URLs in content to site relative ones
/* Inspired by http://thisismyurl.com/6166/replace-wordpress-static-urls-dynamic-urls/
/* ------------------------------------ */
add_filter('content_save_pre', function( $content ) {
$site_url = get_bloginfo('url');
return str_replace(' href=\"'.$site_url, ' href=\"', str_replace(' src=\"'.$site_url, ' src=\"', $content));
}, 10, 1);
@5A5K1A
5A5K1A / wordpress-hook-admin-dashboard.php
Last active February 27, 2017 01:01
WordPress Add all CPT (& tax) to WP Dashboard Right Now Widget
<?php
/* ------------------------------------ */
/* Add Custom Post Type to WP-ADMIN Right Now Widget
/* ------------------------------------ */
add_action( 'dashboard_glance_items', function() { ?>
<style>
#dashboard_right_now a.post_type_name-count:before { content: "\f473"; }
</style>
<?php
$args = array(
@5A5K1A
5A5K1A / wordpress-hooks-metabox.php
Last active February 27, 2017 01:03
WordPress Change custom taxonomy metabox (checkboxes to radios, in order to force one)
<?php
/* Custom Tax Metabox : remove the current custom taxonomy metabox
/* -------------------------------------------------- */
add_action( 'admin_menu', function(){
remove_meta_box('customtaxdiv', 'posttype', 'normal');
});
/* Custom Tax Metabox : add a new & improved custom taxonomy metabox (select-one)
/* -------------------------------------------------- */
add_action( 'add_meta_boxes', function() {
@5A5K1A
5A5K1A / wordpress-hooks-metabox.php
Created February 27, 2017 01:04
WordPress Change 'Featured Image' metabox
<?php
/* Featured Image Metabox : change the text in the current metaboxes
/* -------------------------------------------------- */
add_filter( 'admin_post_thumbnail_html', function( $content ) {
if(get_post_type() == 'post') {
$content = str_replace('Uitgelichte afbeelding', 'Nieuws foto', $content);
// $content .= '<p>Een extra uitlegtekst.</p>';
} elseif(get_post_type() == 'page') {
$content = str_replace('Uitgelichte afbeelding', 'Header foto', $content);
@5A5K1A
5A5K1A / wordpress-hooks-admin.php
Created February 27, 2017 01:06
WordPress Rename WP standard 'Berichten' to 'Nieuws'
<?php
/* rename WP standard 'Berichten' to 'Nieuws'
/* ------------------------------------ */
add_action( 'admin_menu', function() {
global $menu;
global $submenu;
$menu[5][0] = 'Nieuws';
$submenu['edit.php'][5][0] = 'Nieuws';
$submenu['edit.php'][10][0] = 'Nieuw nieuws';
$submenu['edit.php'][16][0] = 'Nieuws Tags';
@5A5K1A
5A5K1A / wordpress-hooks-admin.php
Created February 27, 2017 01:06
WordPress Remove Dashboard sections for "simple users"
<?php
/* Hide certain admin sections for "simple users"
/* -------------------------------------------------- */
add_action('wp_dashboard_setup', function() {
if( current_user_can('editor') ) {
remove_meta_box('dashboard_quick_press', 'dashboard', 'side'); //Quick Press widget
remove_meta_box('dashboard_recent_drafts', 'dashboard', 'side'); //Recent Drafts
remove_meta_box('dashboard_primary', 'dashboard', 'side'); //WordPress.com Blog
remove_meta_box('dashboard_secondary', 'dashboard', 'side'); //Other WordPress News
remove_meta_box('dashboard_incoming_links', 'dashboard', 'normal'); //Incoming Links
@5A5K1A
5A5K1A / wordpress-hooks-admin.php
Last active March 1, 2017 17:41
WordPress Change the standard WP 'Enter title here'
<?php
add_filter( 'enter_title_here', function( $title ) {
if( get_post_type() == 'page' ) {
$title = __('Vul een paginatitel in', 'domain');
} elseif( get_post_type() == 'post' ) {
$title = __('Vul een korte en bondige titel in', 'domain');
}
return $title;
});
@5A5K1A
5A5K1A / wordpress-hooks-admin.php
Last active April 12, 2018 12:36
WordPress Admin Color Scheme
<?php
function custom_admin_color_scheme() {
wp_admin_css_color(
'scheme_name',
__('Scheme Name', 'domain'),
admin_url("/css/colors/scheme_name/colors.css"),
array('#07273E', '#14568A', '#07273E', '#07273E'),
array('base' => '#e5f8ff', 'focus' => '#fff', 'current' => '#fff')
);
@5A5K1A
5A5K1A / wordpress-hooks-translate.php
Created March 2, 2017 18:31
WordPress LocoTranslate Add domain
<?php
filter_gettext( function($key, $translation, $domain) {
if( $key == $translation ) { }
if( $domain =='' ) { $domain = 'domain'; }
return __($key, $domain);
});
@5A5K1A
5A5K1A / wordpress-code.php
Created March 2, 2017 18:37
WordPress Code Copy Safety
<?php
wp_die('You pasted the code without reading it...');