Vantage Child Theme Tutorial – Functionality

The mantra we give our customers is “always create a child theme” but how do you customize functionality with a child theme? This tutorial will show you how.

Before proceeding you should consider the following…

  • You should have an basic understanding of PHP
  • You should be able to use FTP to add or remove files from your hosting server
  • You should back up all of your files and database before proceeding with the steps outlined below
  • Know that you proceed at your own risk – AppThemes does not support customizations of any kind
  • You also might want to read our other tutorial on creating child themes for Vantage

Start by creating a bare bones child theme style.css file:

/*
Theme Name:     Vantage Example Functional Child Theme
Theme URI:      http://appthemes.com/
Description:    Example child theme for the Vantage theme 
Author:         AppThemes
Author URI:     http://appthemes.com/
Template:       vantage
Version:        0.1.0
*/
 
@import url("../vantage/style.css");

Now create a blank child theme functions.php file:

<?php

// BEFORE USING: Move the vantage-child theme into the /themes/ folder.
//
// You can add your own actions, filters and code below.

We are going to accomplish these 3 things in this fast-paced tutorial.

  • Remove the Admin Bar
  • Create a widget that will display all of the links that were in the admin bar
  • Quick and easy swapping of the Vantage’s i18n text strings

Removing the Admin Bar

So, you want to remove the admin bar that appears on the top of the page, well a child theme is one great way to do that without needing to modify Vantage’s code. Here is how easy this will be.

In your child theme’s functions.php file, add this code (below the ‘// You can add your own actions, filters and code below.’):

if ( !is_admin() ) {
	add_filter( 'show_admin_bar', '__return_false', 1000 );
}

So, what does this do? If you are not on a wp-admin page, don’t show the admin bar. Wow, that was easy, right? Now, you’re looking at that empty space up there and thinking, wait a second, weren’t there some useful Vantage specific links in that admin bar? Yes, you are correct. Let me give you a simple demonstration of how to reproduce them some place else.

In your functions.php file again, below the lines you just added in the previous step, add the following sets of code. I’ll explain a little about each:

This function will create a permalinks enabled independent getter function for the Vantage dashboard URL

function va_child_get_user_dashboard_url() {
	global $va_options;
 
	if ( !is_user_logged_in() )
		return;
 
	$listings_permalink = $va_options->dashboard_listings_permalink;
	$permalink = $va_options->dashboard_permalink;
 
	if ( get_option('permalink_structure') != '' ) {
		$url = home_url( user_trailingslashit( $permalink ) );
	} else {
		$url = home_url( '?dashboard='.$listings_permalink.'&dashboard_author=self' );
	}
 
	return $url;
}

Here is the code to produce a very very barebones widget. It’s focus isn’t to try to be the best widget, it’s trying to get you up and running to get those links back so your users can login, logout, register, retrieve their lost password, view their dashboard, and edit their profile. You could, of course, take the different URL getter functions and do however you wish with them.

class VA_Child_Widget_Admin_Bar_Links extends WP_Widget {
 
	function __construct() {
		$widget_ops = array(
			'description' => __( 'All the links that were in the admin bar.', APP_TD )
		);
 
		parent::__construct( 'admin_bar_links', __( 'Vantage - Admin Bar Links', APP_TD ), $widget_ops );
	}
 
	function widget( $args, $instance ) {
		extract( $args );
 
		echo $before_widget;
 
		$li = '';
		if ( is_user_logged_in() ) {
			$li .= html( 'li', html_link( va_child_get_user_dashboard_url(), __( 'Dashboard', APP_TD ) ) );
			$li .= html( 'li', html_link( appthemes_get_edit_profile_url(), __( 'Edit Profile', APP_TD ) ) );
			$li .= html( 'li', html_link( wp_logout_url( home_url() ), __( 'Logout', APP_TD ) ) );
 
		} else {
			$li .= html( 'li', html_link( wp_login_url(), __( 'Login', APP_TD ) ) );
			$li .= html( 'li', html_link( appthemes_get_password_recovery_url(), __( 'Lost Password?', APP_TD ) ) );
			if ( get_option( 'users_can_register' ) ) {
				$li .= html( 'li', html_link( appthemes_get_registration_url(), __( 'Register', APP_TD ) ) );
			}
		}
 
		echo html( 'ul', $li );
 
		echo $after_widget;
	}
}

This function and hook will just get the above widget registered so you can use it in the wp-admin widgets page to put it in some sidebars. Also, you would only need the below if you were using the widget from above.

function va_child_register_widgets() {
	register_widget( 'VA_Child_Widget_Admin_Bar_Links' );
}
add_action( 'widgets_init', 'va_child_register_widgets' );

Now you have the widget registered, so go drag it into a sidebar, and now you can login and logout, and do everything you could with the admin bar, just without the admin bar.

Quick and Easy i18n Text String Swapping

In this little example, you can swap out the text strings in the Vantage theme, without all the language packs. This is most useful and makes the best sense for a use case if you are interested in swapping out a few or a small handful of strings. If you have larger needs, then you might consider using the language packs to swap out strings.

add_filter( 'gettext', 'va_child_wordsmith', 10, 3 );
function va_child_wordsmith( $translated, $orig_text, $domain ) {
	// In this simple example, we only want to look at the strings from the parent theme's text domain (APP_TD).
	if( APP_TD !== $domain )
		return $translated;
 
	$different_wording = va_child_different_wordings( $orig_text );
	if ( !empty( $different_wording ) )
		return $different_wording;
 
	return $translated;
}
 
function va_child_different_wordings( $orig_text ) {
	$strings = array(
		// 'Old string' => 'New string',
		'Business Listings' => 'Listings',
		'(e.g. restaurant, web designer, florist)' => '(Example: Auto Repair, Restaurant)'
	);
 
	return !empty( $strings[$orig_text] ) ? $strings[$orig_text] : '';
}

So, all you would do is change the $strings array to hold your ‘old’ string and your ‘new’ string, and it will swap it out for you!

These are some simple examples of how to override the parent theme’s (Vantage) functionality. There are many more things that could be accomplished, so keep an eye out for more tutorials and enjoy!

Like this tutorial? Subscribe and get the latest tutorials delivered straight to your inbox or feed reader.

Your rating: none
Rating: 4.1 - 14 votes

Popular Add-ons

Authorize.Net

Easily start accepting online payments via credit card and e-check.


(6)
$39

2Checkout

Accept up to eight payment methods, fifteen languages, & twenty six…


(4)
$39

Fortumo SMS payment gateway

Fortumo sms payment gateway for ClassiPress


(3)
$39