Skip to content

Instantly share code, notes, and snippets.

Avatar

Rikard Degler BeyondTheLoop

View GitHub Profile
@BeyondTheLoop
BeyondTheLoop / add-body-class-wp-posts-no-featured-image.txt
Last active Oct 10, 2018
Add body class to WordPress posts without featured image
View add-body-class-wp-posts-no-featured-image.txt
@BeyondTheLoop
BeyondTheLoop / execute-php-wp-widget.txt
Last active Oct 10, 2018
Executing PHP code in WordPress text widget
View execute-php-wp-widget.txt
/**
*
* Executing PHP code in WordPress text widget
*
*/
function execute_php($html){
if(strpos($html,"<"."?php")!==false){
ob_start();
eval("?".">".$html);
@BeyondTheLoop
BeyondTheLoop / disable-gutenberg-wordpress-5
Last active Dec 20, 2018
Disable Gutenberg editor in WordPress 5.x
View disable-gutenberg-wordpress-5
/**
*
* Disable Gutenberg Editor for all post types
*
*/
// disable for posts
add_filter('use_block_editor_for_post', '__return_false', 10);
// disable for post types
@BeyondTheLoop
BeyondTheLoop / get_alt_value_image_id_wordpress.txt
Last active May 23, 2019
Get alt value of image by ID in WordPress
View get_alt_value_image_id_wordpress.txt
/**
*
* Get alt value of image by ID
*
*/
alt="<?php echo get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ); ?>
@BeyondTheLoop
BeyondTheLoop / functions.php
Created Dec 1, 2020
Change WooCommerce message after adding product to cart
View functions.php
function custom_add_to_cart_message() {
$message = 'New message' ;
return $message;
}
add_filter( 'wc_add_to_cart_message_html', 'custom_add_to_cart_message' );
@BeyondTheLoop
BeyondTheLoop / gist:6a57226351ff647622e5adf64f266ff8
Created Apr 1, 2021
Change the page title tag in Enfold title container
View gist:6a57226351ff647622e5adf64f266ff8
/*
* Change the page title tag in Enfold title container
*/
function change_title_container_title_tag($args){
$args['heading'] = 'p';
return $args;
}
add_filter('avf_title_args', 'change_title_container_title_tag', 10, 1);
@BeyondTheLoop
BeyondTheLoop / functions.php
Created Apr 11, 2021
Function to add a new WordPress admin user
View functions.php
function add_new_admin_account(){
$user = 'Username';
$pass = 'Password';
$email = 'email@domain.com';
if ( !username_exists( $user ) && !email_exists( $email ) ) {
$user_id = wp_create_user( $user, $pass, $email );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
}
}