Skip to content

Instantly share code, notes, and snippets.

View softiconic's full-sized avatar

Softiconic softiconic

View GitHub Profile
@softiconic
softiconic / gist:890cfd3ced2ecabed1fd20a196b14ca3
Last active December 2, 2023 18:44
Create a custom post with categories - Wordpress
//career post
function create_job() {
register_post_type( 'job',
array(
'labels' => array(
'name' => __( 'Career' , 'softiconic'),
'singular_name' => __( 'Career' , 'softiconic'),
'add_new' => __('Add New Career', 'softiconic'),
'edit_item' => __('Edit Career', 'softiconic'),
'new_item' => __('New Career', 'softiconic'),
@softiconic
softiconic / custom.js
Last active December 2, 2023 18:45
JavaScript filter functionality.
var container = $('.filter-container');
var elements = $('.filter-container > *');
var buttons = $('.filter-buttons a');
// set all elements active
elements.addClass('selected elements');
// remove select all filter
$('.filter-buttons a.select-all').remove();
buttons.click(function(){
// set all elements inactive by first call
@softiconic
softiconic / custom.html
Last active December 2, 2023 18:45
Customize file upload functionality for input elements.
.upload-btn-wrapper input[type=file] {
position: absolute;
font-size: 14px;
top: 0;
color: #141414;
right: 0;
}
input[type="file"]::-webkit-file-upload-button {
background: transparent;
border: 0;
@softiconic
softiconic / router-index.js
Last active December 2, 2023 18:46
In Vue.js, scroll from the top to the bottom of a routed page.
scrollBehavior (to, from, savedPosition) {
if (savedPosition) {
return savedPosition
} else {
return { x: 0, y: 0 }
}
}
or try,
@softiconic
softiconic / share.html
Last active December 2, 2023 18:46
Create a custom share link with specified title and text message.
<a title="Share on Facebook" target="_blank" rel="noopener noreferrer"
href="https://www.facebook.com/sharer/sharer.php?u=url-here"> Facebook </a>
<a title="Share on Twitter" target="_blank" rel="noopener noreferrer"
href="https://twitter.com/intent/tweet?text=text here"> Twitter </a>
<a title="Share on LinkedIn" target="_blank" rel="noopener noreferrer"
href="https://www.linkedin.com/shareArticle?mini=true&amp;url=#/&amp;title=Title&amp;summary=
Test here&amp;source=LinkedIn">LinkedIn </a>
@softiconic
softiconic / custom.css
Last active December 2, 2023 18:47
Display a Google Map in grayscale.
#map
{
filter: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg"><filter id="g"><feColorMatrix type="matrix" values="0.3 0.3 0.3 0 0 0.3 0.3 0.3 0 0 0.3 0.3 0.3 0 0 0 0 0 1 0"/></filter></svg>#g');
-webkit-filter: grayscale(100%);
filter: grayscale(100%);
filter: progid:DXImageTransform.Microsoft.BasicImage(grayScale=1);
}
@softiconic
softiconic / custom.js
Last active December 2, 2023 18:47
Hide an Elementor form after submission.
<script>
jQuery(document).ready(function($) {
$(document).on('submit_success', '#formsct', function() {
$submitted_form = $(this);
// $submitted_form.hide();
$(".elementor-form-fields-wrapper").hide();
$('.elementor-message-success').show(); // this is the sucess message that I created.
});
@softiconic
softiconic / function.php
Last active December 2, 2023 18:47
The quantity of products shown per page on the WooCommerce shop page.
/**
* Change number of products that are displayed per page (shop page)
*/
add_filter( 'loop_shop_per_page', 'new_loop_shop_per_page', 20 );
function new_loop_shop_per_page( $cols ) {
// $cols contains the current number of products per page based on the value stored on Options –> Reading
// Return the number of products you wanna show per page.
$cols = 9;
return $cols;
@softiconic
softiconic / funciton.php
Last active December 2, 2023 18:48
The default setting for new products in WooCommerce.
add_filter('woocommerce_default_catalog_orderby', 'misha_default_catalog_orderby');
function misha_default_catalog_orderby($sort_by)
{
return 'date';
}
@softiconic
softiconic / function.php
Last active December 2, 2023 18:48
WooCommerce default setting for stock in orders.
add_filter('posts_clauses', 'order_by_stock_status');
function order_by_stock_status($posts_clauses) {
global $wpdb;
if (is_woocommerce() && (is_shop() || is_product_category() || is_product_tag() || is_product_taxonomy())) {
$posts_clauses['join'] .= " INNER JOIN $wpdb->postmeta istockstatus ON ($wpdb->posts.ID = istockstatus.post_id) ";
$posts_clauses['orderby'] = " istockstatus.meta_value ASC, " . $posts_clauses['orderby'];
$posts_clauses['where'] = " AND istockstatus.meta_key = '_stock_status' AND istockstatus.meta_value <> '' " . $posts_clauses['where'];
}
return $posts_clauses;
}