Skip to content

Instantly share code, notes, and snippets.

View thisbit's full-sized avatar

thisbit thisbit

View GitHub Profile
@thisbit
thisbit / acf_postobject_controls_gb_query.php
Last active May 12, 2023 13:38
This is so clients can order manipulate query block output manually including the orderby
<?php
// remove the top function it is used only to inspect the array so one can figure it out
function apuri_get_your_elements() {
$post_obs = get_field('front_posts');
?>
<pre style="min-height: 100vh; display: flex; flex-direction: column; align-items: flex-start; text-align: left;">
<h2 style="margin-top: 90px" >Check the array content</h2>
@thisbit
thisbit / filter-gb-query.php
Created May 11, 2023 23:11
Alter GenerateBlocks Query Blocks with Grid Builder Facet
<?php
function gb_query_vijesti( $query_args, $attributes ) {
if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'arhiv-vijesti' ) !== false ) {
$query_args['wp_grid_builder'] = 'wpgb-content';
}
return $query_args;
}
add_filter( 'generateblocks_query_loop_args', 'gb_query_vijesti', 10, 2 );
@thisbit
thisbit / post_content_cleanup.php
Last active May 19, 2023 13:02
This ensures posts are clean regardless of the missbehaving people that like to paste all kind of stuff into the editor
<?php
/**
* Remove extraneous whitespace from excerpts on blog posts, post archives and search results
* Double test the output
* Wonder why do this, real life reason here -> https://i.imgur.com/5KD8gOd.png
*/
add_filter( 'run_wptexturize', '__return_false' ); // removes wp feature that makes emdash from two consecutive dashes
function apuri_clean_post_content( $content ){
<?php
// stores visited posts into a cookie
function rv_products_non_logged_in(){
$rv_posts = array();
if ( is_singular('post') && !is_user_logged_in() ){
if(isset($_COOKIE['rv_products']) && $_COOKIE['rv_products']!=''){
$rv_posts = unserialize($_COOKIE['rv_products']);
if (! is_array($rv_posts)) {
@thisbit
thisbit / masonry-wp-gallery.css
Created February 23, 2023 15:03
just add .masonry class to any gallery you wish to make look like masonry
@thisbit
thisbit / query_and_markup.php
Last active February 13, 2023 12:47
Custom grid with filter as a grid item
<section class="custom-loop__wrapper">
<h2>custom loop</h2>
<?php
// WP_Query arguments
$args = array(
'post_type' => array( 'post' ),
);
// The Query
@thisbit
thisbit / post_by_view.php
Last active November 24, 2022 15:37
generateblocks_query_loop_args ordered by post_views_count
<?php
/*
* GenerateBlocks & GeneratePress implementation of post ordering based on post views.
*/
// set the view counter
function getPostViews($postID){
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
@thisbit
thisbit / objects.php
Created October 19, 2022 14:17
learning php objects, basics
<?php
// objects and classes
/**
* Flexible but longform
*/
class Person {
private $name;
private $age;
@thisbit
thisbit / back_to_top.php
Last active October 3, 2022 20:27
Back To Top Button
<?php
/**
* Back to Top button that appears once one scrolls past the full viewport height
* Drop this function into your functions.php, code snippets plugin ...
* You should not need to change anything, but in case your theme does not have #page id in one of top dom elements, change to the one you have
* CSS you can normally edit as you like
*/
function back_to_top() {
?>
@thisbit
thisbit / hide-show.css
Last active September 27, 2022 17:55
hide show anything on scroll
/* we use variables to that hiding fits perfectly with the nav and aside height/width */
:root {
--nav-height: 90px;
--sidebar-width: 120px;
}
/* menu setup */
body nav {
position: fixed;
top: 0;