Skip to content

Instantly share code, notes, and snippets.

@corilam
corilam / plugin.php
Last active January 15, 2023 06:33
WP Shortcode with multi properties
function my_testimonial_accordion($atts){
ob_start();
$newcat = shortcode_atts(array(
'testcat' => '',
), $atts );
if ( $newcat['testcat'] ) {
// Parse type into an array. Whitespace will be stripped.
$newcat['testcat'] = array_map( 'trim', str_getcsv( $newcat['testcat'], ',' ) );
}
@corilam
corilam / page.php
Last active February 11, 2022 19:53
Custom WP Search Field Elementor
// From https://github.com/elementor/elementor/issues/5598
<form class="elementor-search-form" role="search" action="https://website.com" method="get">
<input type="hidden" id="search-param" name="post_type" value="product">
<div class="elementor-search-form__container">
<input placeholder="Search for product..." class="elementor-search-form__input" type="search" name="s" title="Search" value="">
<button class="elementor-search-form__submit" type="submit">
<i class="fa fa-search" aria-hidden="true"></i>
<span class="elementor-screen-only">Search</span>
</button>
</div>
@corilam
corilam / product.html
Created February 25, 2021 09:51
Shopify Accordion
<ul class="product-swatches">
<li class="active-swatch">
<a href="#">
<div class="purple single-swatch"></div>
</a>
</li>
<li>
<a href="#">
<div class="green single-swatch"></div>
</a>
@corilam
corilam / button.html
Last active February 25, 2021 09:48
Good Email Button
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#EB7035" style="padding: 12px 18px 12px 18px; border-radius:3px" align="center"><a href="#" target="_blank" style="font-size: 16px; font-family: Helvetica, Arial, sans-serif; font-weight: normal; color: #ffffff; text-decoration: none; display: inline-block;">Enter Now</a></td>
</tr>
</table>
</td>
</tr>
@corilam
corilam / custom-collection-plugin.php
Last active February 16, 2021 15:27
Object Custom Post Type
<?php
/**
* Plugin Name: Custom Collection Plugin
* Plugin URI: https://thedigitalconcern.com
* Description: Creates a collection custom post type called Objects.
* Version: 1.0
* Requires at least: 5.2
* Requires PHP: 7.2
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
@corilam
corilam / functions.php
Last active November 7, 2019 21:52
Exclude logged in users from Google Analystics
add_action('wp_head','ga_header', 20);
function ga_header() {
if ( !is_user_logged_in()) { ?>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXX-Y', 'auto');
@corilam
corilam / page.php
Created August 24, 2017 13:21
Wordpress Background Image Using Featured Image
<?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'slideshow' );?>
<div style="background-image: url('<?php echo $thumb['0'];?>');" class="large-header-image">
</div>
@corilam
corilam / footer.php
Last active July 25, 2017 08:53
Slide up newsletter subscribe
@corilam
corilam / page.php
Created April 27, 2017 08:44
Wordpress useful snippets
// Site URL
<?php get_site_url(); ?>
// Dynamic Footer Date
<?php the_date('Y'); ?>
// Featured Image as Background Image
<style>.project-card-image{width:200px;height:200px;background-position:center}</style>
<?php $projectbg = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'home-campaigns' );?>
<div class="project-card-image" style="background-image: url('<?php echo $projectbg['0'];?>');"></div>
@corilam
corilam / page.php
Created December 2, 2016 14:31
WPML Get home url of current language
<?php $my_home_url = apply_filters('wpml_home_url', get_option('home')); ?>
<a href="<?php echo $my_home_url; ?>">Home</a>