Skip to content

Instantly share code, notes, and snippets.

View strsar's full-sized avatar

Scott Trsar strsar

View GitHub Profile
@strsar
strsar / helpers.php
Created October 7, 2021 01:42
[WP] Good start to some helper functions w/ lazy loading functions over WP's default...
<?php defined( 'ABSPATH' ) or header( 'Location: /' );
/**
* Helper and utility functions
*/
/**
* Get only excerpt content, not post intro
*/
function get_only_the_excerpt() {
@strsar
strsar / login.php
Created October 7, 2021 01:41
[WP] Brand login
<?php defined('ABSPATH') or header('Location: /');
/**
* Admin login form
*/
add_action('login_enqueue_scripts', function() {
$upload_dir = wp_upload_dir();
echo '<style>#login h1 a, .login h1 a {background-image:url('.$upload_dir['baseurl'].'/site/login.svg);background-size:72px}</style>';
});
@strsar
strsar / profile.php
Created October 7, 2021 01:41
[WP] An unfortunate way to cleanup user profiles...
<?php defined('ABSPATH') or header('Location: /');
/**
* Yup... really the only way... display:none
*/
add_action('admin_head', 'remove_edit_profile_fields_css');
function remove_edit_profile_fields_css() {
echo "<style>
/**
@strsar
strsar / admin.php
Created October 7, 2021 01:40
[WP] Admin starting point after some cleanup
<?php defined('ABSPATH') or header('Location: /');
/**
* Cleanup WP admin and unwanted code...
*/
// Remove actions
remove_action('welcome_panel', 'wp_welcome_panel');
remove_action('dashboard_primary', 'wp_dashboard_primary');
remove_action('admin_color_scheme_picker', 'admin_color_scheme_picker');
@strsar
strsar / options.php
Created October 7, 2021 01:39
[WP] Build ACF options page...
<?php defined('ABSPATH') or header('Location: /');
/**
* Additional option pages
*
* @uses Advanced Custom Fields
* @see https://www.advancedcustomfields.com/resources/get-values-from-an-options-page/
*/
if(function_exists('acf_add_options_page')) {
acf_add_options_sub_page(array(
'page_title' => 'Additional Options',
@strsar
strsar / search.php
Created October 7, 2021 01:38
[WP] Search helpers + include all meta fields in default search query
<?php defined('ABSPATH') or header('Location: /');
/**
* Fix search when using smart quotes. Downgrade to straight double quotes.
*/
add_filter('pre_get_posts', 'filter_smart_quote_queries', 10, 1);
add_action('pre_get_posts', 'exclude_posts_from_search');
/**
* Add custom fields data to global WP search
@strsar
strsar / gravityforms.php
Created October 7, 2021 01:37
[WP] Gravity forms overrides
<?php defined('ABSPATH') or header('Location: /');
/**
* Gravity forms
*/
add_filter('gform_init_scripts_footer', '__return_true');
add_filter('gform_disable_print_form_scripts', '__return_true');
/**
* Force Gravity forms to init scripts in the footer...
*
@strsar
strsar / compress.php
Last active May 4, 2022 16:33
[WP] HTML minify class WP_HTML_Compression
<?php defined('ABSPATH') or header('Location: /');
/**
* HTML document compression
*
* Clean and minify all markup
* Wrap `<!--no compression-->` to skip over content
*/
class WP_HTML_Compression {
protected $compress_css = true; // Compress all inline styles
@strsar
strsar / yoast.php
Last active December 1, 2021 01:36
[WP] F*** off to Yoast defaults...
/*
* Yoast SEO Add additional separators to %sep%
* Needed to add pipe "|" back since v17.1
*/
add_filter('wpseo_separator_options', function($separators) {
$additional = array('|');
$separators = array_unique(array_merge($separators, $additional));
return $separators;
}, 10 , 1);
@strsar
strsar / post-type.php
Created October 7, 2021 01:34
[WP] Random custom post type functions
<?php defined('ABSPATH') or header('Location: /');
/**
* Register cpt post type
* `cpt`
*/
function cpt_init() {
$name = 'cpt';
$type = sanitize_title($name);
$labels = array(