Tuesday, 23 January 2018 05:05

Wordpress CSV plugin roundup

Recently I needed a wordpress plugin that allowed me to import a CSV file and store the data into a SQL table. Not knowing any particular plugins I decided to to download, install and test a whole bunch of them - and the results, whilst not always providing a solution to my original problem where still very interesting.

Import CSV files

Download: https://en-au.wordpress.org/plugins/import-csv-files/

A very simple plugin that efficiently imports data from a CSV file and matches it against a variety of post/page related fields. I can see that this plugin would be extremely helpfull for creating pages or posts from a spreadsheet of data. I can already forsee a potential use for this plugin in an upcoming project where I need to migrate much content from static HTML website into a wordpress site.


Download: https://en-au.wordpress.org/plugins/jc-importer/

Another great content importer that matches the CSV data to a variety of wordpess fields. This plugin is very simple to use, and has a number of advanced features in the free version such as the ability to not only map the content to a wordpress post or page, but also a user, taxonomy, or custom post type. The premium version of this plugin allows automated scheduled importing.


Download: https://en-au.wordpress.org/plugins/tablepress/

TablePress allows you to easily create and manage beautiful tables. You can embed the tables into posts, pages, or text widgets with a simple Shortcode. Table data can be edited in a speadsheet-like interface, so no coding is necessary. Tables can contain any type of data, even formulas that will be evaluated. An additional JavaScript library adds features like sorting, pagination, filtering, and more for site visitors. Tables can be imported and exported from/to Excel, CSV, HTML, and JSON files.


Download: https://en-au.wordpress.org/plugins/wptables/

Need to insert a table into your page or post? WordPress Tables plugin will take your data in CSV/JSON format or directly from MySQL table and create an interactive data table. With WPTables plugin, you can easily create and manage your tables from the WordPress administration. Simply insert a shortcode into your page, article or post, and you are ready to go. That’s it! Enjoy your new table.


Download: https://en-au.wordpress.org/plugins/wp-csv-to-database/

WP CSV to Database plugin allows you to insert CSV file content into WordPress database. You can selectively insert data into a particular database table. You can also export any WordPress database table content to a CSV file using this plugin. Useful when you want to bulk upload data from your CSV file (example: product details) to the WordPress database in one go. Bulk data import from CSV (Microsoft Excel) file. Bulk data export from your database to CSV file

Published in Blog
Monday, 30 November -0001 00:00

Modifying wordpress menu code

I've recently needed to modify the wordpress menu code so that I could insert bootstrap classes directly into it.

Add the following to the functions file:

// custom menu example @ https://digwp.com/2011/11/html-formatting-custom-menus/
function clean_custom_menus() {
	$menu_name = 'nav-primary'; // specify custom menu slug
	if (($locations = get_nav_menu_locations()) && isset($locations[$menu_name])) {
		$menu = wp_get_nav_menu_object($locations[$menu_name]);
		$menu_items = wp_get_nav_menu_items($menu->term_id);

		$menu_list = '<nav>' ."\n";
		$menu_list .= "\t\t\t\t". '<ul>' ."\n";
		foreach ((array) $menu_items as $key => $menu_item) {
			$title = $menu_item->title;
			$url = $menu_item->url;
			$menu_list .= "\t\t\t\t\t". '<li><a href="'. $url .'">'. $title .'</a></li>' ."\n";
		$menu_list .= "\t\t\t\t". '</ul>' ."\n";
		$menu_list .= "\t\t\t". '</nav>' ."\n";
	} else {
		// $menu_list = '<!-- no list defined -->';
	echo $menu_list;

Make sure to replace the menu slug. To do this make sure the menu is assigned to a location on Wordpress. The menu slug is infact the location using lowercase and dashes (for example: footer-menu).

It might be necessary to create a new menu potion in the functions file using the following: 

function register_my_menu() {
register_nav_menu('journal',__( 'journal' ));
add_action( 'init', 'register_my_menu' );


To display the menu, insert the following into the theme:

<?php if (function_exists(clean_custom_menus())) clean_custom_menus(); ?>

More information on this function at this blog post

Published in Blog

The following solutions pertain to the excellent wordpress plug Advanced Custom Fields.

To display fields outside of teh wordpress posts loop use the following code but replace the post ID 123:

$value = get_field( "text_field", 123 );
echo $value;

More info here - and here's how to do it inside the loop.

What about repeater fields?

I'm glad you asked. Here's a PHP snippet to echo the values for a repeating field that I've called logo (just remember to change the ID 1862 to match the post or page ID):

while( have_rows('repeater', 1862) ): the_row();

Output individual fields contained with a group field

Advanced Custom Fields allows the grouping of fileds into a single group field. The following will output individual sub fields (remember to replace the post ID):

$group_field = get_field( "my_group_field", 5563 );
echo $group_field['my_sub_field'];

Published in Blog

This is a super handy snippet that will display a specific pages content. It's very usefull to display content in a module or widget area outside of the main content area.

Published in Blog
Wednesday, 12 July 2017 08:29

Display a widget title

The following is a snippet of code I used to display a widget with the ID video title after the widget (rather than before the widget).

<?php $sidebar_id = 'video';
$sidebars_widgets = wp_get_sidebars_widgets();
$widget_ids = $sidebars_widgets[$sidebar_id];
foreach( $widget_ids as $id ) {
$wdgtvar = 'widget_'._get_widget_id_base( $id );
$idvar = _get_widget_id_base( $id );
$instance = get_option( $wdgtvar );
$idbs = str_replace( $idvar.'-', '', $id );
} ?>

<section id="video">
<div class="inner">
<div class="container">
<?php dynamic_sidebar( 'video' ); ?>
<?php echo $instance[$idbs]['title']; ?>


Published in Blog

These two functions create anchor links, and you can customize a lot of it, but it's impossible to add a class through just using their parameters alone. Use the themes functions.php file to give these links a classname:

add_filter('next_posts_link_attributes', 'posts_link_attributes');
add_filter('previous_posts_link_attributes', 'posts_link_attributes');

function posts_link_attributes() {
return 'class="styled-button"';


Published in Blog

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">
$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>';
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.

$pagetype = get_post_type( $post_id );

echo $pagetype;

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

Published in Blog
Page 3 of 5