Skip to content

Instantly share code, notes, and snippets.

View softiconic's full-sized avatar

Softiconic softiconic

View GitHub Profile
@softiconic
softiconic / custom.js
Last active December 2, 2023 18:39
Items in Isotope Masonry are overlapping.
$(window).on('load', function() {
var $container = $('.members_results');
$container.imagesLoaded( function() {
$container.isotope({
itemSelector : '.block-member',
layoutMode : 'masonry',
percentPosition: true
});
});
@softiconic
softiconic / custom.php
Last active December 2, 2023 18:39
Detect if the user is on a laptop or mobile device using browser checks.
<?php
function getBrowser()
{
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$browser = "N/A";
$browsers = [
'/msie/i' => 'Internet explorer',
'/firefox/i' => 'Firefox',
'/safari/i' => 'Safari',
@softiconic
softiconic / single-custom.php
Last active December 2, 2023 18:40
Navigate through custom post types using next and previous functionality.
<?php if (is_singular('post_type_here')) { ?>
<div class="sc-nav">
<div class="sc_prev-next"><?php previous_post_link('%link', 'Previous') ?></div>
<div class="sc_prev-next"><?php next_post_link('%link', 'Next') ?></div>
</div><?php } ?>
@softiconic
softiconic / custom.html
Last active December 2, 2023 18:40
Page loader or customized preloader.
<div class="loader" style="display:block" ></div>
<style type='text/css'>
.loader{
display: none;
}
.loader {
position: fixed;
left: 0px;
top: 0px;
@softiconic
softiconic / function.php
Last active December 2, 2023 18:41
Elementor not found - query.
add_action('elementor/query/query_results', function($query) {
$total = $query->found_posts;
if ($total == 0) {
echo '<p class="text-align-center">No items found.</p>';
}
});
@softiconic
softiconic / hook-vc-grid.php
Last active December 2, 2023 18:41
How to resolve the error "Compilation failed: invalid range in character class at offset."
/wp-content/plugins/js_composer/include/autoload/hook-vc-grid.php
And edit line 86, from:
. '([\\w-_]+)' // 2: Shortcode name
to
. '([\\w\-_]+)' // 2: Shortcode name
@softiconic
softiconic / function.php
Last active December 2, 2023 18:42
Track WordPress post views without using a plugin.
function gt_get_post_view() {
$count = get_post_meta( get_the_ID(), 'post_views_count', true );
return "$count views";
}
function gt_set_post_view() {
$key = 'post_views_count';
$post_id = get_the_ID();
$count = (int) get_post_meta( $post_id, $key, true );
$count++;
update_post_meta( $post_id, $key, $count );
@softiconic
softiconic / function.php
Last active December 2, 2023 18:43
Include Elementor anchor with an offset.
add_action( 'wp_footer', function() {
if ( ! defined( 'ELEMENTOR_VERSION' ) ) {
return;
}
?>
<script>
window.addEventListener('elementor/frontend/init', function() {
elementorFrontend.hooks.addFilter( 'frontend/handlers/menu_anchor/scroll_top_distance', function( scrollTop ) {
return scrollTop - 180;
@softiconic
softiconic / custom.php
Last active December 2, 2023 18:43
Loop through custom posts filtered by custom taxonomies in WordPress.
<?php
// Get all the categories
$categories = get_terms( 'sccategory' );
// Loop through all the returned terms
foreach ( $categories as $category ):
// set up a new query for each category, pulling in related posts.
$services = new WP_Query(
array(
@softiconic
softiconic / config.js
Last active December 2, 2023 18:44
Allow the video tag in CKEditor.
CKEDITOR.editorConfig = function (config) {
config.allowedContent = true;
};