Skip to content

Instantly share code, notes, and snippets.

/**
* Class Elementor_Form_Email_Attachments
*
* Send Elementor Form upload field as attachments to email
*/
class Elementor_Form_Email_Attachments {
// Set to true if you want the files to be removed from
// the server after they are sent by email
const DELETE_ATTACHMENT_FROM_SERVER = true;
public $attachments_array = [];
@ledovej
ledovej / disable-post-type-archives
Created April 14, 2020 11:00
Disables archives for post-types by 404 page or redirect
/* Disable archives pages */
add_action('template_redirect', 'my_disable_archives_function');
function my_disable_archives_function()
{
/* Conditional checks examples:
is_category()
is_tag()
is_date()
is_author()
@ledovej
ledovej / registering-siderbar-widget
Created February 24, 2020 16:11
Registering a sidebar widget for Wordpress website using functions.php
/*registering sidebar widget*/
if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => 'Blog Sidebar',
'before_widget' => '<div class = "widgetizedArea">',
'after_widget' => '</div>',
'before_title' => '<h4>',
'after_title' => '</h4>',
)
add_action( 'elementor_pro/posts/query/relational-posts', function ( $query ) { $postid = get_the_ID(); $ids = get_post_meta($postid, 'related_featured', true); if ( $ids ) { $query->set( 'post__in', $ids ); } } );
@ledovej
ledovej / duplicate-posts-and-pages
Last active February 24, 2020 16:09
Function that lets you duplicate Wordpress posts and pages without using a plugin
/*
* Function for post duplication. Dups appear as drafts. User is redirected to the edit screen
*/
function rd_duplicate_post_as_draft(){
global $wpdb;
if (! ( isset( $_GET['post']) || isset( $_POST['post']) || ( isset($_REQUEST['action']) && 'rd_duplicate_post_as_draft' == $_REQUEST['action'] ) ) ) {
wp_die('No post to duplicate has been supplied!');
}
/*
@ledovej
ledovej / defer-javascript
Created December 16, 2019 13:31
Defer javascript
function defer_parsing_of_js( $url ) {
if ( is_user_logged_in() ) return $url; //don't break WP Admin
if ( FALSE === strpos( $url, '.js' ) ) return $url;
if ( strpos( $url, 'jquery.js' ) ) return $url;
return str_replace( ' src', ' defer src', $url );
}
add_filter( 'script_loader_tag', 'defer_parsing_of_js', 10 );
@ledovej
ledovej / elementor-accordion-closed-tweak
Created December 16, 2019 13:22
Elementor accordion tweak to keep first tab closed
function elementor_accordion_title() { ?>
<script>
jQuery(document).ready(function() {
jQuery( '.elementor-accordion .elementor-tab-title' ).removeClass( 'elementor-active' );
jQuery( '.elementor-accordion .elementor-tab-content' ).css( 'display', 'none' );
});
</script>
<?php }
add_action( 'wp_footer', 'elementor_accordion_title', 99 );
@ledovej
ledovej / cookie-footer-script-wordpress
Last active February 24, 2020 16:10
Cookie consent script for wordpress websites - WPML translatable