A big thankyou to Evan Herman over at Code Parrots who helped me out with the following solution to an request that I submitted. He has developed a terrific timeline plugin for Wordpress, that is very flexible and looks super jazzy.

Published in Blog
Tuesday, 23 May 2017 02:17

Creating new editor styles in Tiny MCE

Here is a handy snippet that will allow you to create your own preformatted custom styles within the Wordpress text editor. The new styles are selected by a drop down field titled Formats. 

Published in Blog
Sunday, 21 May 2017 16:50

Modifying Wordpress user info

The following adds a bunch of usefull social media links to the wordpress user profiles - and also allows simple HTML within the user bio. Add this code to the theme functions.php file.

/*===================================================================================
* Add Author Links
* =================================================================================*/
function add_to_author_profile( $contactmethods ) {

$contactmethods['rss_url'] = 'RSS URL';
$contactmethods['google_profile'] = 'Google Profile URL';
$contactmethods['twitter_profile'] = 'Twitter Profile URL';
$contactmethods['facebook_profile'] = 'Facebook Profile URL';
$contactmethods['instagram_profile'] = 'Instagram Profile URL';
$contactmethods['linkedin_profile'] = 'Linkedin Profile URL';

return $contactmethods;
}
add_filter( 'user_contactmethods', 'add_to_author_profile', 10, 1);
//disable WordPress sanitization to allow more than just $allowedtags from /wp-includes/kses.php
remove_filter('pre_user_description', 'wp_filter_kses');
//add sanitization for WordPress posts
add_filter( 'pre_user_description', 'wp_filter_post_kses');

 

Now dial it all up within the author.php file of your theme with the following code:

<div id="description" class="node"><?php the_author_meta('description'); ?></div>


<ul class="icons">
<?php
$site = get_the_author_meta( 'user_url' );
if ( $site && $site != '' ) {
echo '<li class="site"><a target="_blank" href="' . esc_url($site) . '">Website</a></li>';
}


$rss_url = get_the_author_meta( 'rss_url' );
if ( $rss_url && $rss_url != '' ) {
echo '<li class="rss"><a target="_blank" href="' . esc_url($rss_url) . '">RSS</a></li>';
}

$google_profile = get_the_author_meta( 'google_profile' );
if ( $google_profile && $google_profile != '' ) {
echo '<li class="google"><a target="_blank" href="' . esc_url($google_profile) . '" rel="author">Google+</a></li>';
}

$twitter_profile = get_the_author_meta( 'twitter_profile' );
if ( $twitter_profile && $twitter_profile != '' ) {
echo '<li class="twitter"><a target="_blank" href="' . esc_url($twitter_profile) . '">Twitter</a></li>';
}

$facebook_profile = get_the_author_meta( 'facebook_profile' );
if ( $facebook_profile && $facebook_profile != '' ) {
echo '<li class="facebook"><a target="_blank" href="' . esc_url($facebook_profile) . '">Facebook</a></li>';
}

$linkedin_profile = get_the_author_meta( 'linkedin_profile' );
if ( $linkedin_profile && $linkedin_profile != '' ) {
echo '<li class="linkedin"><a target="_blank" href="' . esc_url($linkedin_profile) . '">Linkedin</a></li>';
}

$instagram_profile = get_the_author_meta( 'instagram_profile' );
if ( $instagram_profile && $instagram_profile != '' ) {
echo '<li class="Instagram"><a target="_blank" href="' . esc_url($instagram_profile) . '">Instagram</a></li>';
}
?>
</ul>
Published in Blog
Thursday, 27 April 2017 05:44

Get entry type. Is it a post or a page?

Here's a handy little snippet that determines if an entry is a post or page within a loop. I found this usefull for determining the entry type within search results, where I wanted to style the results differently depending on what type of result it was.


<?php
$pagetype = get_post_type( $post_id );

echo $pagetype;

if ($pagetype == "post") {
// do something
}
?>

Published in Blog
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(); ?>

<?php
$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*" />
</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
Page 1 of 2