Skip to content

Instantly share code, notes, and snippets.

View barbwiredmedia's full-sized avatar

Barbara Talbot barbwiredmedia

View GitHub Profile
@barbwiredmedia
barbwiredmedia / timecompare.php
Created November 15, 2013 00:45
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-->
@barbwiredmedia
barbwiredmedia / referer.php
Last active July 25, 2024 16:03
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/' ) ;
@barbwiredmedia
barbwiredmedia / functions.php
Created May 15, 2014 23:30
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;
@barbwiredmedia
barbwiredmedia / template.php
Created August 18, 2014 22:10
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 } ?>
@barbwiredmedia
barbwiredmedia / admin-functions.php
Last active July 25, 2024 15:50
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'
);
@barbwiredmedia
barbwiredmedia / trim-words.php
Last active July 24, 2024 18:15
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;
?>
@barbwiredmedia
barbwiredmedia / functions.php
Last active February 23, 2023 23:55
Wordpress SEO Yoast Order meta box. This will change the priority of Yoasts meta box and move it to the bottom of all pages / posts.
// Move Yoast Meta Box to bottom
function yoasttobottom() {
return 'low';
}
add_filter( 'wpseo_metabox_prio', 'yoasttobottom');
@barbwiredmedia
barbwiredmedia / functions.php
Created July 15, 2014 20:42
Hide ACF menu item from the admin menu. wordpress functions.php
/**
* Hide ACF menu item from the admin menu
*/
function remove_acf_menu()
{
// provide a list of usernames who can edit custom field definitions here
$admins = array(
'levy-access',
@barbwiredmedia
barbwiredmedia / paginate.php
Last active October 31, 2021 02:37
Wordpress pagination - paginate links http://codex.wordpress.org/Function_Reference/paginate_links No plugins required. Minor styling needed OR used bootstrap assitance: http://www.ordinarycoder.com/paginate_links-class-ul-li-bootstrap/
<?php echo paginate_links( $args ); ?>
<!--OR-->
<?php
//custom paginaiton with styling from bootstrap
function custom_pagination() {
global $wp_query;
$big = 999999999; // need an unlikely integer
$pages = paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
@barbwiredmedia
barbwiredmedia / gulpfile.js
Last active July 14, 2021 07:39
Gulp File , sass, browser-sync, local development. Assumes folder structure /assets/styles/ & /assets/js/
var gulp = require('gulp');
var gutil = require('gulp-util');
var sass = require('gulp-sass');
var browserSync = require('browser-sync').create();
var reload = browserSync.reload;
gulp.task('sass', function () {
gulp.src('./assets/styles/**/*.scss')
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))