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*" />
</div>',

'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*" />
</div>',

'url' =>
'<div
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>
</div>', )
),

'comment_field' => '<div>' .

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

'</div>',

'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:


// Changing excerpt more
function new_excerpt_more($more) {
global $post;
return '… <a href="'. get_permalink($post->ID) . '">' . 'Read More &raquo;' . '</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
Wednesday, 18 November 2015 12:17

Changing relationships in SQL

The following changes the relationships between worldpress posts and their category, although it can be modified for other uses.

the example changes posts in category ID #10 and places them in category ID #20

UPDATE wp_term_relationships 
SET term_taxonomy_id = 
   (SELECT term_taxonomy_id FROM wp_term_taxonomy WHERE term_id =10)WHERE term_taxonomy_id =
   (SELECT term_taxonomy_id FROM wp_term_taxonomy WHERE term_id =20)
Published in Blog
Page 2 of 3