Skip to content

Instantly share code, notes, and snippets.

View robertpassaro's full-sized avatar

Bob Passaro robertpassaro

View GitHub Profile
@robertpassaro
robertpassaro / dynamic-copyright-statement.php
Last active June 21, 2016 14:40
Template tag that echoes html output for a copyright string on the page; includes option to have a "starting year" as well as the current year.
@robertpassaro
robertpassaro / query-loop-over-terms.php
Last active March 25, 2016 17:08
WP template code to query a post type according to terms from a custom taxonomy -- and loop through to divide the posts by term
<div class="page-content">
<?php
// Specify the taxonomy and post type for the queries.
$fq_post_type = 'xxxxpost_typexxxxx';
$fq_taxonomy = 'xxxtaxonomyxxx';
$term_args = array(
'orderby' => 'title',
/*--------------------------------------------------------------
# Google Analytics script (gets called into head element)
--------------------------------------------------------------*/
function fq_google_analytics() {
$google_ua_code = 'xxxxxxxxxxxxx'; // Add "UA" code for this site from Google
echo "<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
/*
==== Wrap video embeds in a div so they can be made responsive
(will need to have appropriate css in place)
.embed-container iframe {position:absolute;top:0;left:0;width:100%;height:100%}
*/
add_filter( 'embed_oembed_html', 'fq_wrap_embed', 10, 3 );
/*
* WORDPRESS
* Template tag that echoes a notice that there is an SSL connection on the current page. Returns false if not.
*
* @param (string) $text Optional. The text to be displayed if there is an SSL connection.
* @param (bool) $icon Optional. If true, echos a span for a lock icon.
*/
function the_secure_connection( $icon=true, $text='Secure connection' ) {
/*
* Keep WordPress native custom-post-type archive view, while redirecting any single views back to the archive.
* To use when single views are not wanted or needed.
* Takes no parameters.
*/
add_action( 'template_redirect', 'fq_disable_single_cpt_views' );
function fq_disable_single_cpt_views() {
/*
* FQ website credit line
*
* Template tag that echoes html for a website credit line for FQ;
* includes option to have a small logo appear in either black or white.
*
* @param (string) $text Optional. Text you want displayed before link and FQ name. Defaults to "Website by".
* @param (string) $logo Optional. Whether to display a version of our logo. Accepted values are 'black', 'white, or false. Defaults to false.
*
* Example: the_fq_credit( 'Website developed by', 'white' );
// Handy function to get next/prev post of any post type, based on any ordering criteria
function fq_get_nearest_posts( $post_type=null, $orderby='menu_order', $order='ASC' ) {
$args = array(
'post_type' => $post_type ? $post_type : get_post_type(),
'orderby' => $orderby,
'order' => $order,
'posts_per_page' => -1,
);
function fq_remove_yoast_columns( $columns ) {
// remove the Yoast SEO columns
unset( $columns['wpseo-score'] );
unset( $columns['wpseo-title'] );
unset( $columns['wpseo-metadesc'] );
unset( $columns['wpseo-focuskw'] );
unset( $columns['wpseo-score-readability'] );
return $columns;
}