Skip to content

Instantly share code, notes, and snippets.

View softiconic's full-sized avatar

Softiconic softiconic

View GitHub Profile
@softiconic
softiconic / gist:378ef276c1bb724f6ef632017abc6263
Last active December 2, 2023 18:37
Change background color on scroll
// Function to handle the intersection of the observed element
function handleIntersection(entries, observer) {
entries.forEach(entry => {
const targetSection = document.getElementById('tetosection'); // Replace 'my-section' with your section's ID
if (entry.target === targetSection) {
if (entry.isIntersecting) {
targetSection.classList.add('highlightsc');
} else {
targetSection.classList.remove('highlightsc');
@softiconic
softiconic / gist:866a0275432d823fca581dbeaec8f640
Last active December 2, 2023 18:36
Create a sticky header and a footer that moves from the bottom to the top using HTML, CSS, and JavaScript.
<a id="sctop">
<span> <svg enable-background="new 0 0 32 32" id="Слой_1" version="1.1" viewBox="0 0 32 32" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><path clip-rule="evenodd" d="M26.704,10.192l-9.999-9.899 c-0.397-0.393-1.03-0.378-1.428,0l-9.999,9.9c-0.394,0.391-0.394,1.024,0,1.414c0.395,0.391,1.034,0.391,1.429,0l8.275-8.192V31 c0,0.552,0.452,1,1.01,1s1.01-0.448,1.01-1V3.414l8.275,8.192c0.394,0.391,1.034,0.391,1.428,0 C27.099,11.216,27.099,10.583,26.704,10.192z" fill="#121313" fill-rule="evenodd" id="Arrow_Upward"/><g/><g/><g/><g/><g/><g/></svg></span>
</a>
<script>
//this for header sticky
jQuery(document).ready(function($) {
$(window).on('scroll', function (){
var sticky = $('.scheader'),
scroll = $(window).scrollTop();
@softiconic
softiconic / gist:359c4b07e2bac114040455d0546cdd5c
Last active December 2, 2023 18:35
Hamburger menu with hover effect
<div class="scmenu-link-w act" id="sc81">
<div class="scmenu-link is--top"></div>
<div class="scmenu-link is--btm"></div>
</div>
div#elementor-popup-modal-373 {
z-index: 555!important;
}
@softiconic
softiconic / gist:147864cacc4f66762fef616770536d30
Last active December 2, 2023 18:35
JavaScript code snippet for displaying More/Less functionality.
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script type="text/javascript">
var $ = jQuery;
$(document).ready(function(){
$('.show-more').on('click', function(){
event.preventDefault()
$(this).toggleClass('content-hide')
$(this).closest('.profile-card').find('.show-less, .details-area').toggleClass('content-hide')
})
@softiconic
softiconic / functions.php
Last active December 2, 2023 18:34
Convert WordPress URL/Slug from lowercase to uppercase.
//this for SLUG url lowercase to uppercase
add_filter( 'sanitize_title', 'wpse5029_sanitize_title_with_dashes', 10, 3 );
function wpse5029_sanitize_title_with_dashes($title, $raw_title, $context = 'display') {
$title = strip_tags( $raw_title );
// Preserve escaped octets.
$title = preg_replace( '|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title );
// Remove percent signs that are not part of an octet.
$title = str_replace( '%', '', $title );
// Restore octets.
@softiconic
softiconic / custom.js
Last active December 2, 2023 18:34
Smart Preloader for WordPress
window.addEventListener('load', function(event) {
fadeAway();
function fadeAway() {
var delay = 1000; // Adjust the delay in milliseconds as needed
var duration = 500; // Adjust the duration in milliseconds as needed
// Check if jQuery is defined and if not, load it
if (typeof jQuery === 'undefined') {
var script = document.createElement('script');
@softiconic
softiconic / custom.js
Last active December 2, 2023 18:34
Add or remove a class in a section-based loop for multiple items.
$(document).ready(function() {
$('.scshow').click(function() {
var parentDiv = $(this).closest('.scteto');
if (parentDiv.hasClass('highlighted')) {
parentDiv.removeClass('highlighted');
} else {
parentDiv.addClass('highlighted');
}
});
@softiconic
softiconic / gist:d2b2a154ac68884e37ffd9966a54d1c3
Last active December 2, 2023 18:33
Create a custom post navigation in WordPress
<?php
add_shortcode( 'fs_prev_next_thumbs', 'generate_faq_landing_link_shortcode' );
function generate_faq_landing_link_shortcode( $atts, $content ) {
global $post; // if outside the loop
$prev_next = '';
$prev_post = get_previous_post();
$next_post = get_next_post();
@softiconic
softiconic / functions.php
Last active December 2, 2023 18:33
Restrict access to the media library in WordPress.
// Limit media library access
add_filter( 'ajax_query_attachments_args', 'wpb_show_current_user_attachments' );
function wpb_show_current_user_attachments( $query ) {
$user_id = get_current_user_id();
if ( $user_id && !current_user_can('activate_plugins') && !current_user_can('edit_others_posts
') ) {
$query['author'] = $user_id;
}
@softiconic
softiconic / gist:e67bd602f90466fe47c310e16b427446
Last active December 2, 2023 18:33
WooCommerce single product - navigate to the next or previous product.
//add_action( 'woocommerce_before_single_product', 'add_custom_text_before_product_title' );
add_shortcode( 'scnextprev', 'productnextprev_shortcode' );
function productnextprev_shortcode(){
echo '<div class="prev_next_buttons">';
// 'product_cat' will make sure to return next/prev from current category
$previous = next_post_link('%link', '&larr; %title', TRUE, ' ', 'product_cat');
$next = previous_post_link('%link', '%title &rarr;', TRUE, ' ', 'product_cat');