Skip to content

Instantly share code, notes, and snippets.

View dgoze's full-sized avatar
💭
I may be slow to respond.

Daniel dgoze

💭
I may be slow to respond.
View GitHub Profile
@dgoze
dgoze / timecompare.php
Created July 25, 2024 16:03 — forked from barbwiredmedia/timecompare.php
Wordpress Working with time datepicker in javascript and ACF meta date. Reformat time for use by persons and show different content depending on if the date has passed.
<?php
// http://php.net/manual/en/function.date.php
//get the time from the ACF time picker see php.net for date formats
$printdate = DateTime::createFromFormat('Ymd', get_post_meta($post->ID, 'event_date', 'true')); //event_date from custom feild
$eventDate = $printdate->format('m/d/Y');
if (time() < strtotime("$eventDate 11:59PM")) { ?>
<!-- the date has not passed SHOW CONTENT -->
<?php } else { ?>
<!-- SORRY the date has passed already-->
@dgoze
dgoze / referer.php
Created July 25, 2024 16:03 — forked from barbwiredmedia/referer.php
Checking for page referer in php. Wordpress redirect or header refresh
<?php
//check for refering page to switch content based on referrer
$referrer = $_SERVER['HTTP_REFERER'];
if ($referrer == 'http://url.com' or $referrer == 'http://url-2.com') {
//Matches YES!
} else {
//Matches NO!
header( 'Location: http://www.url.com/no-soup-for-you/' ) ;
@dgoze
dgoze / functions.php
Created July 25, 2024 16:03 — forked from barbwiredmedia/functions.php
Wordpress filter the_excerpt to include page formatting on output, trim excerpt length. From Aaron Russell: http://aaronrussell.co.uk/legacy/improving-wordpress-the_excerpt/
//Excerpt with formating from WYSIWYG
function improved_trim_excerpt($text) {
global $post;
if ( '' == $text ) {
$text = get_the_content('');
$text = apply_filters('the_content', $text);
$text = str_replace('\]\]\>', ']]&gt;', $text);
$text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
//$text = strip_tags($text, '<p>');
$excerpt_length = 70;
@dgoze
dgoze / template.php
Created July 25, 2024 16:03 — forked from barbwiredmedia/template.php
Wordpress: H1 headlines on different pages.Single / singular / archive
<h1>
<?php if (is_singular('your_cpt') || is_archive('your_cpt') || is_post_type_archive('your_cpt') ) { ?>
YOUR CPT NAME
<?php } elseif (is_search()) { ?>
Search
<?php } elseif (is_404()) { ?>
Error 404
<?php } else { ?>
<?php the_field('headline_text'); ?>
<?php } ?>
@dgoze
dgoze / admin-functions.php
Created July 25, 2024 15:50 — forked from barbwiredmedia/admin-functions.php
Edit and Hide Admin menu items admin_menu & admin_bar_menu. Also hide items from the item bar
function remove_acf_menu()
{
// provide a list of usernames who can edit custom field definitions here
$admins = array(
'admin',
'levy-admin',
'barb'
);
{
"title": "JSON schema for WordPress blocks",
"$schema": "http://json-schema.org/draft-04/schema#",
"definitions": {
"//": {
"reference": "https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/",
"attributesReference": "https://developer.wordpress.org/block-editor/reference-guides/block-api/block-attributes/",
"contextReference": "https://developer.wordpress.org/block-editor/reference-guides/block-api/block-context/",
"supportsReference": "https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/",
"registerReference": "https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/#example-optional"
@dgoze
dgoze / sort-by-acf-repeater-field.php
Created July 24, 2024 18:15 — forked from bmoredrew/sort-by-acf-repeater-field.php
Sort Posts by ACF Repeater Field Using Multidimensional Array
<?php
// Create an empty array for storage
$post_data = array();
// Set arguments for your query
$args = array(
'post_type' => 'trips',
'posts_per_page' => 999
);
@dgoze
dgoze / trim-words.php
Created July 24, 2024 18:15 — forked from barbwiredmedia/trim-words.php
Wordpress trim words shorten post meta / custom field. ACF wp_trim_words create an excerpt. http://codex.wordpress.org/Function_Reference/wp_trim_words
<?php
$content = get_post_meta($post->ID, your_custom_field_meta, true);
$trimmed_content = wp_trim_words($content, 15, '... <a href="' . get_permalink() . '">Read More</a>');
echo $trimmed_content;
?>
<?php echo get_option('home'); ?> <!-- get the home URL -->
<?php bloginfo('description'); ?> <!-- display the blog description -->
<?php bloginfo('name'); ?> <!-- display the blog name -->
<?php bloginfo('template_directory') ?> <!-- get the home URL for template's directory -->
<?php echo get_template_directory_uri(); ?>
<?php wp_list_pages('sort_order=desc&title_li='); ?> <!-- display the page list in descending order withour title -->
<?php wp_list_pages('sort_order=desc&depth=1&title_li='); ?> <!-- display the page list in descending order with "current_page_item" class
<?php wp_list_bookmarks(); ?> <!-- display the list of blogrolls -->
<?php echo date('Y'); ?>
@dgoze
dgoze / readonly_and_disabled_to_text_acf.php
Created July 24, 2024 18:14 — forked from vovadocent/readonly_and_disabled_to_text_acf.php
Readonly and disabled to ACF text field
<?php
add_action('acf/render_field_settings/type=text', 'add_readonly_and_disabled_to_text_field');
function add_readonly_and_disabled_to_text_field($field) {
acf_render_field_setting( $field, array(
'label' => __('Read Only?','acf'),
'instructions' => '',
'type' => 'radio',
'name' => 'readonly',
'choices' => array(
1 => __("Yes",'acf'),