This is a list of useful WordPress functions that I often reference to enhance or clean up my sites. Please be careful and make backups.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Sets the default categories | |
function add_the_categories() { | |
$categories = array( | |
'Case Study', | |
'Blog', | |
'Article' | |
); | |
foreach( $categories as $category ) { | |
$exists = term_exists( $category, 'category' ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Copy compiled Oxygen page content to post_content for search */ | |
function sg_save_rendered_page_content( $meta_id, $object_id, $meta_key, $meta_value ) { | |
// Debugging | |
// $debug .= preg_replace( '#(\[/[^\]]+?\])#', "$1\n", $meta_value ); | |
// file_put_contents( plugin_dir_path( __FILE__ ) . 'debug.html', $debug ); | |
if ( 'ct_builder_shortcodes' != $meta_key ) return; | |
// Don't try to render anything with inner content | |
if ( false !== strpos( $meta_value, '[ct_inner_content' ) ) return; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
merge_slashes on; | |
if ($request_uri ~* "\/\/+") { | |
rewrite ^/(.*) $scheme://$host/$1 permanent; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if [ "$EUID" -ne 0 ];then | |
>&2 echo "This script requires root level access to run" | |
exit 1 | |
fi | |
if [ -z "${WORDPRESS_DB_PASSWORD}" ]; then | |
>&2 echo "WORDPRESS_DB_PASSWORD must be set" | |
>&2 echo "Here is a random one that you can paste:" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Valid values: development, staging and production. To get this value use: wp_get_environment_type() | |
defined( 'WP_ENVIRONMENT_TYPE' ) or define( 'WP_ENVIRONMENT_TYPE', 'production' ); | |
define('DB_NAME', 'fill in db name'); | |
define('DB_USER', 'fill in username'); | |
define('DB_PASSWORD', 'fill in db password'); | |
define('DB_HOST', 'localhost'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function theme_enqueue_styles() { | |
wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( 'avada-stylesheet' ) ); | |
wp_enqueue_style( 'custom-style', get_stylesheet_directory_uri() . '/assets/css/custom.css', array() ); | |
wp_enqueue_style( 'responsive-style', get_stylesheet_directory_uri() . '/assets/css/responsive.css', array() ); | |
} | |
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' ); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# netplan2NM.sh | |
# Ubuntu server 20.04 Change from netplan to NetworkManager for all interfaces | |
echo 'Changing netplan to NetowrkManager on all interfaces' | |
# backup existing yaml file | |
cd /etc/netplan | |
cp 01-netcfg.yaml 01-netcfg.yaml.BAK |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Oxygen Builder Generate automatic meta description | |
function sp_titles_template_variables_array($array) { | |
$array[] = '%%oxygen%%'; | |
return $array; | |
} | |
add_filter('seopress_titles_template_variables_array', 'sp_titles_template_variables_array'); | |
function sp_titles_template_replace_array($array) { | |
if ( is_plugin_active( 'oxygen/functions.php' ) && function_exists( 'ct_template_output' ) && ! isset( $_GET['ct_builder'] ) ) { | |
add_filter( 'wp_doing_ajax', '__return_true' ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Enqueue all js codes combined in a single file. | |
function enqueue_theme_assets() | |
{ | |
wp_enqueue_script( | |
'trackers', | |
get_stylesheet_directory_uri() . '/js/trackers.js', | |
null, | |
null, |