Skip to content

Instantly share code, notes, and snippets.

@nicmare
nicmare / remove-blocksy-patterns.php
Last active August 1, 2025 09:21
This snippet removes the default patterns and "blocksy" pattern category created by blocksy theme
<?php
add_action("init", "init_blocks_and_patterns",100);
function init_blocks_and_patterns(){
if(\WP_Block_Pattern_Categories_Registry::get_instance()->is_registered("blocksy")){
unregister_block_pattern_category( 'blocksy');
$blocksy_patterns = [
"posts-layout-1",
"posts-layout-2",
"posts-layout-3",
"posts-layout-4",
@nicmare
nicmare / blocksy-ajax-search.php
Last active February 1, 2024 10:19
This Code Snippet modifies the Wordpress Search Terms
<?php
function search_replacement($term){
return ltrim(str_replace( array('0x'), array('0 x '), urldecode(strtolower($term)) ));
}
// ajax search:
function replace_search( $query_object )
{
if( $query_object->is_search() ) {
$raw_search = $query_object->query['s'];
<?php
function default_archive_card_img($args){
if(empty($args["featured_image"]))
$args["featured_image"] = blocksy_media(array(
"attachment_id"=>get_page_by_path("default_image_name")->ID,
'ratio' => '4/3',
'class' => 'boundless-image',
'tag_name' => 'a',
'size' => "medium_large",
'html_atts' => [
<?php
// change blocksy_blocks layout
add_filter("do_shortcode_tag",function($output, $tag, $attr, $m ){
if($tag != "blocksy_posts") return $output;
if(!empty($attr["layout"]) && in_array($attr["layout"],["grid","enhanced-grid","simple","classic","gutenberg"])){
$p = new \WP_HTML_Tag_Processor( $output );
if ( $p->next_tag(array( 'class_name' => 'entries' )) ) {
if($p->get_attribute( 'data-layout' )){
$p->set_attribute( 'data-layout', $attr["layout"] );
$output = $p->get_updated_html();
<?php
function update_read_more_buttons($text,$domain,$key){
if($key != "set_archive_archive_read_more_text") return $text; // identify your target $key by using error_log($key) and WP_DEBUG Constant
return sprintf(__("%1\$s <span class='sr-only' style='display: none'>about %2\$s</span>","your_domain"),$text,get_the_title());
}
add_filter("wpml_translate_single_string",'update_read_more_buttons',10,3);
<?php
function set_media_folder($pid = ""){
if(empty($pid)) return;
if(get_post_type($pid) == "attachment"){
if(($path = get_attached_file($pid)) && str_contains($path,"nsl_avatars")) {
if ( $term_avatars = get_term_by( 'slug', 'avatare', 'happyfiles_category' ) )
wp_set_object_terms( $pid, $term_avatars->term_id, 'happyfiles_category' );
wp_update_post([
'ID' => $pid,
<?php
/* usage:
** [blocksy_search]
** [blocksy_search placeholder="Try the Search"]
** [blocksy_search post_type="locations" height="60px"]
** [blocksy_search no_liveresults="true" fontsize="22px" padding="20px"]
*/
function blocksy_search($args, $content){
if(!function_exists("blocksy_isolated_get_search_form")) return "";
$args = wp_parse_args($args);
<?php
function maybe_output_content_hook($content,$id){
if(get_post_type() != "set") return $content;
$is_unknown = (get_post_meta(get_the_ID(),"sync_status",1) == "unknown_item")??false;
if($is_unknown && get_the_title($id) == "Set-View")
$content = "";
if(!$is_unknown && get_the_title($id) == "Set-View: Syncing")
<?php
function set_image_link_to_loop_image($html, $args){
if(get_bloginfo("version") < 6.2) return $html;
if(!isset($args["attrs"]["isLink"])) return $html;
$p = new \WP_HTML_Tag_Processor( $html );
if ( $p->next_tag("a") ) {
$p->set_attribute( 'href', get_the_post_thumbnail_url() );
$html = $p->get_updated_html();
@nicmare
nicmare / acf-getfield-shortcode.php
Last active January 30, 2023 06:31
simple function to place acf field values where ever needed in content
<?php
function acf_get_field_shortcode($args = array()){
if(!function_exists("get_field")) return "";
$field = (isset($args["field"]) && !empty($args["field"]))?get_field($args["field"]):false;
if($field) return $field;
return "";
}
add_shortcode("acf_get_field","acf_get_field_shortcode");