Skip to content

Instantly share code, notes, and snippets.

@reanim8ed
reanim8ed / sample.php
Last active August 29, 2019 21:40
[CF7 edit form HTML output] #wordpress #CF7
function op111_wpcf7_main_add_class($output, $tag, $atts, $m) {
if ($tag === 'contact-form-7' && $atts['title'] === 'Main') {
$output = str_replace(
'wpcf7-submit',
'wpcf7-submit wpcf7-submit-main',
$output
);
}
return $output;
@reanim8ed
reanim8ed / sample.js
Last active August 29, 2019 21:40
[Fire event on successful CF7 form sent] #wordpress #CF7
document.addEventListener( 'wpcf7mailsent', function( event ) {
if(event.detail.contactFormId == 'wpcf7-f3112-o2') {
//put your code here
}
}, false );
@reanim8ed
reanim8ed / sample.php
Last active August 29, 2019 21:41
[Change Yoast meta tags] #wordpress #SEO #Yoast
More info: https://www.ibenic.com/programmatically-change-yoast-seo-open-graph-meta/
/**
* Function to add hooks and filter out the Yoast SEO Open Graph Meta Tags
*/
function change_yoast_seo_og_meta() {
add_filter( 'wpseo_opengraph_title', 'change_title' );
add_filter( 'wpseo_opengraph_desc', 'change_desc' );
add_filter( 'wpseo_opengraph_url', 'change_url' );
add_action( 'wpseo_add_opengraph_images', 'add_images' );
@reanim8ed
reanim8ed / sample.php
Last active February 8, 2020 08:24
[Disable menu options and updates] #wordpress
// Don't disable on dev
if ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) {
// Disable core update checking
add_filter( 'pre_site_transient_update_core', create_function( '$a', "return null;" ) );
remove_action( 'admin_init', '_maybe_update_core' );
remove_action( 'wp_version_check', 'wp_version_check' );
// Remove the updates menu item
function yell_remove_update_menu() {
remove_submenu_page( 'index.php', 'update-core.php' );
}
@reanim8ed
reanim8ed / sample.php
Created August 29, 2019 21:44
[Enque inline JS without file] #wordpress
wp_register_script( 'dummy-handle-footer', '', [], '', true );
wp_enqueue_script( 'dummy-handle-footer' );
wp_add_inline_script( 'dummy-handle-footer', 'console.log( "footer" );' );
@reanim8ed
reanim8ed / sample.php
Created August 29, 2019 21:46
[REST API example] #wordpress
<?php
// Register REST API endpoints
class GenerateWP_Custom_REST_API_Endpoints {
/**
* Register the routes for the objects of the controller.
*/
public static function register_endpoints() {
// endpoints will be registered here
@reanim8ed
reanim8ed / sample.php
Created August 29, 2019 21:47
[Remove type from scripts] #wordpress #W3
/**
* Remove type attribute from scripts
*/
public function clean_script_tag($input) {
if ( ! is_admin() ) {
$input = str_replace( "type='text/javascript' ", '', $input );
return str_replace( "'", '"', $input );
}
return $input;
}
@reanim8ed
reanim8ed / sample.php
Last active February 8, 2020 08:24
[Prevent update notification for specific plugins] #wordpress
/**
* Prevent update notification for plugin
* http://www.thecreativedev.com/disable-updates-for-specific-plugin-in-wordpress/
* Place in theme functions.php or at bottom of wp-config.php
*/
function disable_plugin_updates( $value ) {
$pluginsToDisable = [
'plugin-folder/plugin.php',
'plugin-folder2/plugin2.php'
];
@reanim8ed
reanim8ed / sample.php
Last active September 30, 2019 11:22
[Clean metaboxes]#wordpress
/**
* Clean metaboxes
*/
add_action('admin_init', 'mp_set_user_metaboxes');
function mp_set_user_metaboxes($user_id=NULL) {
$meta_key['hidden'] = 'metaboxhidden_dashboard';
$meta_value = array(
'dashboard_incoming_links',
'wpseo-dashboard-overview',
'dashboard_activity',
@reanim8ed
reanim8ed / sample.php
Created October 2, 2019 06:45
[Move attachment to uploads folder] #wordpress
if( isset($this->data['file']) ) {
$allowed_types = array('image/png', 'image/jpg', 'application/pdf', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'xls', 'application/msword', 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' );
if ( in_array($this->data['file']['type'], $allowed_types) ) {
//move temp file
$upload_dir = wp_upload_dir();
$upload_dir = $upload_dir['path'];