Skip to content

Instantly share code, notes, and snippets.

@nicmare
nicmare / blc-layout-themejson-filter.php
Last active September 28, 2022 09:43
use theme.json along with Blocksy Customizer Content Width settings
<?php
function blocksy_layout_update($editor_settings, $block_editor_context){
// default values:
$editor_settings["__experimentalFeatures"]["layout"]["contentSize"] = "var(--has-wide, var(--block-max-width))";
$editor_settings["__experimentalFeatures"]["layout"]["wideSize"] = "calc(var(--block-max-width) + 260px)";
// maybe add offset values:
if($mods = get_theme_mods())
if(isset($mods["wideOffset"]))
$editor_settings["__experimentalFeatures"]["layout"]["wideSize"] = "calc(var(--block-max-width) + ".($mods["wideOffset"]*2)."px)";
return $editor_settings;
<?php
echo do_shortcode("[borlabs-cookie id='youtube' type='content-blocker'][youtubeplayer id=".$inhalt["ytid"]."][/borlabs-cookie]");
?>
<?php
// conditionally load sal.js assets
function lmdm_animation_scripts(){
if(is_singular()) {
$blocks = parse_blocks(do_shortcode(get_post(get_the_ID())->post_content));
if(is_array($blocks)){
foreach($blocks as $block){
if(isset($block["attrs"]["effect"]) && !empty($block["attrs"]["effect"])){
wp_enqueue_style('saljs-style', get_stylesheet_directory() . '_js/saljs/sal.css');
wp_enqueue_script('lmdm-saljs', get_stylesheet_directory() . '_js/saljs/sal.js', null, "1.0");
@nicmare
nicmare / add-blocksy-bodyclasses.php
Last active December 13, 2022 14:22
checks if header and/or footer is disabled on page and adds a body class
<?php
function add_blocksy_bodyclasses($classes){
if($blocksy = get_post_meta(get_the_ID(),"blocksy_post_meta_options",true)){
if(isset($blocksy["disable_header"]) && $blocksy["disable_header"] == "yes")
$classes[] = "blocksy-header-disabled";
if(isset($blocksy["disable_footer"]) && $blocksy["disable_footer"] == "yes")
$classes[] = "blocksy-footer-disabled";
}
return $classes;
<?php
function editor_font_sizes($unitOnly = false, $lineHeightOnly = false){
if($rootFont = get_theme_mod("rootTypography")){
$rootFontSize = "16px";
$rootLineHeight = 1.3;
if(isset($rootFont["size"]["desktop"]))
$rootFontSize = $rootFont["size"]["desktop"];
@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");
<?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();
<?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
/* 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 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,