Tuesday, 21 February 2017 11:46

Custom post types in a loop

The following creates a loop of custom post types. This example creates a testimomnials block. 

<?php $loop = new WP_Query( array( 'post_type' => 'testimonial',
'posts_per_page' => 4 )
); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

$clientname = (types_render_field( "client-name", array( 'raw' => true) ));
$quote = (types_render_field( "quote", array( 'raw' => true) ));

<p><?php echo $quote; ?>&nbsp;<span><?php echo $clientname; ?></span></p>

<?php endwhile; wp_reset_query(); ?>

Check this article for more information

Published in Blog

Put the following in the themes functions.php file:

function is_blog () {
global $post;
$posttype = get_post_type($post );
return ( ((is_archive()) || (is_author()) || (is_category()) || (is_home()) || (is_single()) || (is_tag())) && ( $posttype == 'post') ) ? true : false ;

Test it using the following conditional within your theme:

<?php if (is_blog()) { echo 'You are on a blog page'; } else { echo 'no blog'; } ?>
Published in Blog
Wednesday, 11 January 2017 01:09

Modifying the comments form

Take a look in the themes comments.php file and you will see a line where the comments area is called in using:

<?php comment_form(); ?>

In some cases I found it was contained within a conditional like this:

if ( comments_open() ) comment_form();

You can replace it with the following code, injecting in any modifications to the fields as you need:

if ( comments_open() ) { ?>

<?php $comment_args = array( 'title_reply'=>'Leave a reply',

'fields' => apply_filters( 'comment_form_default_fields', array(

'author' =>
'<div class="row">
<div class="large-4 columns comment-form-author">' .
'<input id="author"
name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) .
'" size="30"' . $aria_req . ' placeholder="Name*" />

'email' =>
'<div class="large-4 columns comment-form-email">' .
'<input id="email" name="email" type="text"
value="' . esc_attr( $commenter['comment_author_email'] ) .
'" size="30"' . $aria_req . ' placeholder="Email*" />

'url' =>
class="large-4 columns comment-form-url">' .
'<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) .
'" size="30"
placeholder="Website" />
</div>', )

'comment_field' => '<div>' .

'<textarea id="comment" name="comment" cols="45" rows="8" aria-required="true" placeholder="Comment*"
></textarea>' .


'comment_notes_after' => '',


comment_form($comment_args); ?>

<?php } ?>
Published in Blog
Wednesday, 11 January 2017 00:17

Changing the default "read more" link

This function tells WordPress to remove the default more which looks like this: […], and replace it with a link.

Open your functions.php file, and paste the following code inside the php tags:

Note: check your parent theme to find the appropriate function to be removed.

function child_theme_setup() {
// override parent theme's 'more' text for excerpts
remove_filter( 'excerpt_more', 'blankslate_excerpt_read_more_link' );
remove_filter( 'get_the_excerpt', 'blankslate_excerpt_read_more_link' );
add_action( 'after_setup_theme', 'child_theme_setup' );

// Replaces the excerpt "Read More" text by a link
function new_excerpt_more($more) {
global $post;
return '<a class="moretag" href="'. get_permalink($post->ID) . '"> Read the full article...</a>';
add_filter('excerpt_more', 'new_excerpt_more');

Published in Blog
Tuesday, 22 November 2016 11:03

Adding widget areas using functions.php

The following code inserted into your child themes functions.php file will create two new widget areas called banner and dropmenu:

* Register our sidebars and widgetized areas.
function arphabet_widgets_init() {

register_sidebar( array(
'name' => 'banner',
'id' => 'banner',
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h2 class="rounded">',
'after_title' => '</h2>',
) );

register_sidebar( array(
'name' => 'dropmenu',
'id' => 'dropmenu',
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h2 class="rounded">',
'after_title' => '</h2>',
) );


add_action( 'widgets_init', 'arphabet_widgets_init' );


Create a hook in your theme by using the following: 

<?php dynamic_sidebar( 'dropmenu' ); ?>
Published in Blog
Saturday, 17 September 2016 02:28

Echo the page name

Here is a quick and wasy way to display the page heading inside a wordpress template:

<h1 class="pageheading"><?php global $post;
echo $post->post_title; ?></h1>

Published in Blog
Wednesday, 20 July 2016 01:46

Disable all plugins using mySQL

Sometimes when trying to log into the wordpress back end I get the dreaded whitescreen of death. This is usually caused by a plugin. The solution is usually realtively painless: disable all the plugins. This fixes the admin login whitescreen issue. Plugins can then be enabled individually, checking to see which plugin breaks the login page.

Published in Blog

The following is a conditional to do something if the post is contained within wither of these three categories:

<?php if (in_category( array( gallery,this,another ) )) {
echo 'BINGO!!';
} ?>
Published in Blog

Before you proceed, please note that the code below will remove featured images from all posts on your WordPress site by simply just pasting. Also note that this code will not delete any of your uploaded images, they will still be available in Media Library and you can reuse them anytime.

All you need to do is copy and paste this code in your theme’s functions.php file.

global $wpdb;
$wpdb->query( "
    DELETE FROM $wpdb->postmeta 
    WHERE meta_key = '_thumbnail_id'
" );

As soon as you save your functions.php file this script will run a database query and remove featured images from all posts.

Important: Please remove this code immediately after saving your functions.php file. You will not be able to set featured images in WordPress as this code will keep removing featured images from posts.


Published in Blog

A client needed the events calender to display shortened day headings in the monthly view. Here are two possible solutions:

  1. The following shows M T W T F S S in the monthly view:
    Override the 
    month/loop-grid.php template and, in your custom version, find this line of code: $days_of_week = tribe_events_get_days_of_week();
    Replace it with: $days_of_week = tribe_events_get_days_of_week( true );

  2. The following shows MON TUE WED THU FRI SAT SUN in the monthly view:
    Override the 
    month/loop-grid.php template and, in your custom version, find this line of code:
    <th id="tribe-events-<?php echo esc_attr( strtolower( $day ) ); ?>" title="<?php echo esc_attr( $day ); ?>" data-day-abbr="<?php echo esc_attr( $wp_locale->get_weekday_abbrev( $day ) ); ?>"><?php echo $day ?></th>
    replace with:
    <th id="tribe-events-<?php echo strtolower($day) ?>" title="<?php echo $day ?>"><?php echo substr($day, 0, 3); ?></th>
Published in Blog
Page 4 of 5