Theme Code Snippets

All themes

This creates a background transition effect in the footerwrap from one color to another.


#footerwrap{
	background: none;
	background-color: #45CEEF;
	-webkit-animation: colorpulse 40s infinite alternate;
	animation: colorpulse 40s infinite alternate;
}
@-webkit-keyframes colorpulse {
	0%   { background-color: #45CEEF; }
	25%  { background-color: #FFF5A5; }
	50%  { background-color: #FFD4DA; }
	75%  { background-color: #99D2E4; }
	100% { background-color: #D8CAB4; }
}
@keyframes colorpulse {
	0%   { background-color: #45CEEF; }
	25%  { background-color: #FFF5A5; }
	50%  { background-color: #FFD4DA; }
	75%  { background-color: #99D2E4; }
	100% { background-color: #D8CAB4; }
}

Use a different image size for attachment pages

WordPress by default uses the Medium image size for images displayed in attachment pages. To change that you can use this snippet.


<?php
 
function custom_attachment_size( $content ) {
	if( is_attachment() ) {
		global $post;
		$content = wp_get_attachment_image( $post->ID, 'large' );
	}
	return $content;
}
add_filter( 'the_content', 'custom_attachment_size' );

Disable URL field in the comments form

In the comments form there's a text field where visitors can leave the URL to their website. If you want to hide that, use this snippet:


<?php
 
function custom_comment_form_fields( $fields ) {
    unset( $fields['url'] );
    return $fields;
}
add_filter( 'comment_form_default_fields', 'custom_comment_form_fields' );

Issue with custom fonts on Firefox

Firefox has strict requirements where the font resides in relation to the website, sometimes this causes issues where the custom fonts on your site are not loaded. To fix that, you need to add the following code in the .htaccess file located in the root of your WordPress installation.


<FilesMatch "\.(ttf|otf|woff)$">
<IfModule mod_headers.c>
        Header set Access-Control-Allow-Origin "*"
</IfModule>
</FilesMatch>

Issue with audio playback

If you're having trouble rewinding or forwarding the audio files on your site, it could mean that the Range headers for the audio file are not setup properly. Click here for more information. You can ask your web hosting provider to fix this issue for you.

Hide header and footer inside lightbox window

In various modules in Builder (eg. Button module), you have the option to open an URL in a lightbox window. If the source URL is using a Themify theme, it will add a class lightboxed to the body tag (in the iframe tag). You can add custom CSS to target the page in the lightbox. For an example, you can hide the header and footer with this custom CSS:


.lightboxed #headerwrap,
.lightboxed #footerwrap {
    display: none;
}

Theme Settings Cache

The Themify themes cache all the theme settings in a file, which is, by default located in <theme>/themify/.data directory. This reduces the number of database queries thereby increasing the performance of your website. If your server is setup to sync files for backup, this feature may cause your settings to not be saved as expected. In such a case the caching can be easily turned off by adding this snippet into the wp-config.php file:


<?php

define( 'THEMIFY_SKIP_DATA_CACHE', true );

The location where the theme stores the settings cache can also be changed the same say, to do that:


<?php

define( 'THEMIFY_SETTING_CACHE_DIR', __DIR__ . '/wp-content/uploads/tf_datacache/' ); /* Note that the trailing slash at the end is required. */

This changes the path to the "tf_datacache" folder inside wp-content/uploads. You can then assign permissions or change the rules for file sync for that folder depending on your needs and your setup.

Builder

Change module title tags

Builder by default uses h3 tags for module titles, to change that you can use:


<?php

function custom_themify_builder_module_args( $args ) {
    $args['before_title'] = '<h3 class="module-title">';
    $args['after_title'] = '</h3>';
    return $args;
}
add_filter( 'themify_builder_module_args', 'custom_themify_builder_module_args' );

Disable front-end editor

If you want to disable the frontend Builder (without disabling the Builder entirely) you can use the following code in the child theme functions.php file:


<?php

add_filter( 'themify_builder_is_frontend_editor', '__return_false' );

Ultra

Display post title above post date

The post title by default is displayed below the post date. If you want to swap their position, add the following custom CSS:


.post .post-content-inner {
   display: table;
}
.post .post-title {
   display: table-header-group;
}

Split

Change split scroll threshold

By default when screen size gets smaller than 600px, the split scrolling effect is disabled. To change this, you would add this code in a child theme functions.php:


<?php

function custom_split_scroll_threshold( $args ) {
    $args['splitScrollThreshold'] = 890;
    return $args;
}
add_filter( 'themify_script_vars', 'custom_split_scroll_threshold' );

Event

Change the display of map in events page

To change the settings of the map displayed on the event post, the "themify_event_map_args" filter can be used. For example, to disable the mouse wheel zoom on the map, you can use:


<?php

function custom_themify_event_map_args( $args ) {
    $args['scroll_wheel'] = 'no';
    return $args;
}
add_filter( 'themify_event_map_args', 'custom_themify_event_map_args' );

The list of options can be found here: https://themify.me/docs/shortcodes#map

Music

To change the size of the images displayed on the single gallery, you can use:


<?php

function custom_themify_single_gallery_image_size( $size, $featured ) {
	if ( $featured && '' != $featured ) {
		return array(
			'width' => 350,
			'height' => 400
		);
	} else {
		return array(
			'width' => 350,
			'height' => 200
		);
	}
}
add_filter( 'themify_single_gallery_image_size', 'custom_themify_single_gallery_image_size', 10, 2 );

Disable album lightbox

To disable the lightbox that shows up when clicking on the albums, you can use:


<?php

function custom_disable_album_lightbox( $args ) {
    $args['albumLightbox'] = 0;
    return $args;
}
add_filter( 'themify_script_vars', 'custom_disable_album_lightbox' );

Disable the map on events page

To disable the map displayed on the single event:


.single-event .shortcode.map {
    display: none;
}
.single-event #content {
    padding-right: 420px;
    margin-top: 150px;
}
.single-event .event-single-wrap {
    overflow: visible;
}
.single-event .event-map {
    height: auto;
}

Open video posts in lightbox

By default when you click the video post title, it goes to the video single view. You can change the post title link to open video in lightbox by adding the following code in Themify > Settings > General > Footer Code:


<script>
jQuery(function($) {
	$( '.video-multiple .post-title a, .loops-wrapper.video .post-title a' ).click( function(){
		$( this ).closest( '.post' ).find( '.lightbox' ).trigger( 'click' );
		return false;
	} );
} );
</script>

Open album posts in lightbox

Similar as above, to change album post title to open album in lightbox, add the following code in Themify > Settings > General > Footer Code:


<script>
jQuery(function($) {
	$( '.album-multiple .post-title a, .loops-wrapper.album .post-title a' ).click( function(){
		$( this ).closest( '.post' ).find( '.themify-lightbox' ).trigger( 'click' );
		return false;
	} );
} );
</script>

Show past events in event category taxonomy archive

By default only the upcoming events are displayed in the Event category taxonomy pages. To disable this behavior and show all events, you can use:


<?php

function custom_event_category_sort() {
    if( is_tax( 'event-category' ) )
        add_filter( 'themify_theme_event_sorting', '__return_empty_array' );
}
add_action( 'template_redirect', 'custom_event_category_sort' );

Switch map and featured image in single event pages

In single event pages, the map is displayed on the right side while the map goes in the background. To switch the position of the map and the featured image, you can use:



.single-event .event-map {
    height: 200px;
    position: absolute;
    overflow: hidden;
    top: 0;
    right: 0;
    margin-top: 40px;
    margin-right: 40px;
    background: #1a1c1c;
    width: 350px;
    z-index: 2;
}
.single-event .event-single-details {
    position: static;
    max-width: inherit;
}
.single-event .event-single-details .post-image {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1;
}
.single-event .event-single-details .event-info-wrap {
    position: relative;
    z-index: 3;
    max-width: 350px;
    float: right;
    margin-top: 200px;
    background: #000;
}

Parallax

This snippet is useful if you don't want the portfolio images to be linked to the portfolio single.


<?php
 
function custom_unlink_portfolio_images() {
	global $post, $themify;
 
	if( $post->post_type == 'portfolio' && is_singular( 'portfolio' ) ) {
		$themify->unlink_image = 'yes';
	}
}
add_action( 'themify_post_before', 'custom_unlink_portfolio_images' );

Move menu bar to the top of the page

This custom CSS forces the menu bar to be displayed at the top.


#nav-bar {
	top: 0;
	bottom: auto;
	position: fixed;
}
.admin-bar #nav-bar {
	top: 32px;
}
.home #main-nav ul {
	bottom: auto;
}
.home #main-nav ul:before {
	bottom: auto;
	top: -8px;
	border-top: none;
	border-bottom: 8px solid #fff;
}
@media screen and (max-width: 760px) {
	#main-nav {
		top: 100%;
		bottom: auto;
	}
}

Display site logo on sticky header

By default site logo is hidden on sticky header. To show it on sticky header, add this custom CSS:


#headerwrap.fixed-header .header-bar{
  display:block
}
#headerwrap.fixed-header #site-logo {
    position: fixed;
    top: 30px;
    left: 20px;
    font-size:30px;
    z-index: 10000;
}

Left-align header elements in Parallax

To move the site logo, site description and social icons in the header to the left side of the header, add this custom CSS:


#header {
  text-align:left;
}
.header-bar,.sidemenu {
  padding-left:10%
}

Flatshop

Remove product lightbox

This will remove the lightbox displayed when you click the More Info button for products.


<?php

function themify_loop_add_to_cart_link( $format = '', $product = null ) {
	$url = $product->add_to_cart_url();
	if ( function_exists( 'themify_is_touch' ) ) {
		$isPhone = themify_is_touch( 'phone' );
	} else {
		if ( ! class_exists( 'Themify_Mobile_Detect' ) ) {
			require_once THEMIFY_DIR . '/class-themify-mobile-detect.php';
		}
		$detect = new Themify_Mobile_Detect;
		$isPhone = $detect->isMobile() && !$detect->isTablet();
	}
	if( ( 'variable' == $product->get_type() || 'grouped' == $product->get_type() ) && !$isPhone ) {
		$url = add_query_arg( array('post_in_lightbox' => '1'), $url );
		$replacement = 'class="variable-link '; // add space at the end
		$format = preg_replace( '/(class=")/', $replacement, $format, 1 );
		$format = preg_replace( '/href="(.*?)"/', 'href="'.$url.'"', $format, 1 );
	}
	if ( $product->is_purchasable() ) {
		$format = preg_replace( '/add_to_cart_button/', 'add_to_cart_button theme_add_to_cart_button', $format, 1 );
	}
	return $format;
}

Hide the cart icon when it's empty

Hide the cart icon in the header when there is no product in the cart.


<script>
jQuery(function($){
	$('body').on( 'added_to_cart', function(){
		$('#cart-icon').show();
	} );
	if( $('#shopdock .product').length > 0 ) {
		$('#cart-icon').show();
	}
});
</script>

Pinboard

Fluid layout for all pages

On the Pinboard homepage, Pinboard stretches fullwidth of the screen. If you want to have the same fullwidth layout on all pages, use this custom CSS:


.pagewidth {
    width: 94%;
}
@media (min-width: 771px) {
    #content {
        width: 75%;
    }
    #sidebar {
        width: 22%;
    }
}

Metro

Registering a new tile size

Metro theme by default has 3 size options for the Tile post type: Small, Medium and Large. This snippet helps you register a new tile size.


<?php
 
function register_custom_tile_size( $args ) {
	$args[4]['options'][0]['meta'][] = array( 'value' => 'custom', 'img' => 'images/layout-icons/tile-custom.png', 'title' => __( 'Custom', 'themify' ) );
	return $args;
}
add_filter( 'themify_do_metaboxes', 'register_custom_tile_size' );

Now to set the dimensions of this new tile using custom CSS codes:


.tile.custom,
.tile-post.image.custom .tile-flip {
    width: 200px;
    height: 200px;
}

Register new tile colors

Add more color options for Tile post type.


<?php
 
function custom_themify_theme_meta_boxes($arg) {
	array_push($arg[4]['options'][1]['meta'], array('value' => 'cyan', 'img' => 'images/layout-icons/color-cyan.png'));
	array_push($arg[4]['options'][1]['meta'], array('value' => 'silvergrape', 'img' => 'images/layout-icons/color-silvergrape.png'));
	return $arg;
};
add_filter( 'themify_do_metaboxes', 'custom_themify_theme_meta_boxes' );

Elemin

Move post meta to bottom

The theme by default displays the post meta info (author, comment counts, etc.) on the side of the post. This snippet will them to the bottom of the post:


.loops-wrapper.list-post .post-meta,
.single .list-post .post-meta {
	top: 100%;
	width: 100%;
	text-align: left;
}
.loops-wrapper.list-post .post-meta span,
.single .list-post .post-meta span,
.post-meta .post-date {
	display: inline-block;
	margin-right: 10px;
}
.loops-wrapper.list-post .post,
.single .list-post .post {
	padding-left: 0;
}
span.post-icon {
	display: none !important;
}

Read More

Translating Input Text With WPML

WPML not only allows you to translate your posts content but also any text input in theme settings. This article will show you how to have different translated text on the footer text setting.

Translating Text on Themify Panel

In this example, we will translate the footer copyright text. You can follow these same steps to translate any text listed in the theme options.

  1. To edit the footer copyright text in the default language, navigate to Themify -> Themify Settings then click the Theme Settings menu item. Expand the Footer Text section and edit the text in the Footer Text One field then click the Save button.

    Themify Settings

  2. Navigate to WPML -> String Translation and choose Themify text-domain from the Select strings within domain drop-down list. Search for the copyright text. Click on the translations link and add your translated text. Then check the Translation is complete box and click the Save button.

    String Translation

Read More

Changing Share Plugin & Builder Priority

Themify Builder appends its content filtering the post or page content using the_content filter and appending itself. Share plugins like AddThis, ShareThis, Bookmarkify, etc. also use the same method to append content to the post or page. Sometimes they might have conflicts due to their display priority.

Priority is a term used in WordPress actions and filters, and it indicates the order in which the action or filter is executed. Priority goes from 0 to anything. In our particular case with Builder and share plugins, priority will be the order in which these additional contents are appended.

As a reference, Builder appends its content on priority 11, so to add content after Builder's own content, you must use priority 12 or higher.

This tutorial provides sample custom functions to show you how to change the priority of the social buttons so they are added after Builder.

  • create a custom-functions.php file in the theme folder (if it doesn't exist)
  • paste in the following function:

SimpleShareButtons

Reference: http://www.simplesharebuttons.com/wordpress/


<?php
// change priority for SimpleShareButtons
if ( function_exists( 'show_share_buttons' ) ) {
remove_filter( 'the_content', 'show_share_buttons');
add_filter( 'the_content', 'show_share_buttons', 15 );
}
?>

JetPack Sharedaddy

Reference: http://jetpack.me/tag/sharedaddy/


<?php
// Change priority for Shareaholic 
remove_filter( 'the_content', 'sharing_display', 19 );
	remove_filter( 'the_excerpt', 'sharing_display', 19 );
	add_filter( 'the_content', 'sharing_display', 10 );
	add_filter( 'the_excerpt', 'sharing_display', 10 );
?>

Read More

Hook Content

Overview

Hooks, technically called WordPress Action Hooks, allow power users to insert their own custom executable code into WordPress. Think of Hooks as WordPress's 'APIs' (Application Programming Interface). To see what a Hook can do, we have created a demo area to illustrate the power and convenience of Hooks.

In the past, if a user wanted to add custom code via a Hook, they would have had to create a custom-functions.php file for the theme. With release of Themify Framework 1.7.3 this is no longer the case. Themify has given users the function to create and edit their own Hooks without the need to creating a custom-functions.php file.

The following tutorial will guide you through the process of adding custom code to a Hook in the Themify Framework. This tutorial uses the "Basic" theme as a reference, but the steps can be followed with any of our themes. Adding Hooks is only available in Themify Framework 1.7.3. If you are below this version, you will need to upgrade.

Background

Log in to your WordPress Admin area (WP-Admin) and go to the Themify Framework Panel. On the left hand side you will see the entry Hook Content, click it.

screenshot

If the theme is new to you, you should familiarise yourself where within the theme the Hook locations are. To do this, click the See Hook Locations button.

screenshot

The yellow areas depicted in the image above are the Hook function locations within the theme, areas where you can insert your custom code. Click the X to close the preview.

Adding a Hook

In this tutorial, we are going to add a Google Adsense ad in between the navigation menu bar and the main content window. To create a Hook, click the Add item button.

screenshot

You will be presented with the Hook controls.

screenshot

  1. Hook - drop-down menu of all the Hooks that are available in the theme
  2. Conditions - parameters and settings for the Hook
  3. Code window - where you insert your custom function code
  4. Delete - delete the Hook

To select a Hook, just click the drop-down menu (1) and select it in the menu. If you are unsure where the Hook is in the theme, click the 'See Hook Locations' button to find it.

Hook Conditions (2) are the parameters that you set upon the Hook. Conditions range from having the Hook appear on a certain Page or Post like the Homepage, Posts assigned with a specific category like News or just in the Portfolio section. To apply a condition on your Hook, click the +conditions button and check any box that is applicable and then click Save.

screenshot

To insert your code, just type your code or paste it into the editor field.

screenshot

Click Save All when done. Below is the final result.

Spacing and styling can added via the Custom CSS panel in the Themify Framework Panel (Styling > Custom CSS).

Sorting Hooks

Hooks can be arranged in any order you so desired. Click-on and drag the Hook via the 'Drag to Sort' button to place the Hook in the sort order you require. Click Save All when done.

screenshot

Shortcodes

Themify Shortcodes can be used in Hooks for simplicity and speed. To see some in action, checkout our demo area to see what is possible.

If you require a slider on every Post and Page, just insert the ShortCode for a slider:
[post_slider image="yes" image_w="300" image_h="200" visible="3" scroll="1"]

screenshot

To add your Twitter feed in the sidebar but make it appear in Posts only, create a new Hook, select the Hook (siderbar_start)and then add the ShortCode.

screenshot

In the Hook conditions, select General and check the Single post views box. This means the Twitter Feed will only be shown on Posts.

screenshot

Disabling Hook Content feature

To remove the Hook Content panel from Themify page, please follow these steps:
1. Create a custom-functions.php in the theme folder if it does not exist.
2. Paste this in:


<?php

remove_filter( 'themify_theme_config_setup', array( $GLOBALS['themify_hooks'], 'config_setup' ), 12 );

Read More

Remove lightbox link in post title and link to single post

If you want to have only the image link to a lightbox, and not also the title, follow these steps:

1. in WP Admin, go to Themify > General

2. paste the following in the Header Code text area


<script>
jQuery(document).ready(function($){
	$('.post-title a').each(function(){
		var $self = $(this),
		    $article = $self.closest('article'),
		    post_id = $article.attr('id');
		$self.removeClass('themify_lightbox');
		$self.attr( 'href', 'http://'+document.domain + '/?p=' + post_id.replace('post-', '') );
	});
});
</script>

3. save the change and check the site.

Note that this will only work for top level domains.

Read More

Code Snippets

Here you'll find certain snippets to do some general common stuffs in Themify themes. Note that some snippets might not work in all themes.

General procedure to use a snippet

1. Create a child theme and create a functions.php in your child theme folder

2. Edit it, and paste this inserting the snippet you've chosen


<?php

// Snippet code goes here

?>

If you already have a child theme and the functions.php file, you only need to add the PHP code inside the <?php and ?> tags.

Add audio player to home page header


<?php

/**
 * Place an audio player in the header of the front page
 */
function custom_themify_home_audio_player() {
	if( is_front_page() )
		echo do_shortcode( '[audio mp3="http://www.roxyg/wp-content/uploads/YOUR-AUDIO-FILE.mp3" autoplay="true"]' );
}
add_action('themify_header_before', 'custom_themify_home_audio_player');

?>

Display the default Featured Image meta box again


<?php

/**
 * Display WordPress default Featured Image meta box
 */
remove_action('do_meta_boxes', 'themify_cpt_image_box');

?>

Add author capabilities to the "tile" custom post type

This code is generic: if you want to add author capabitilities to portfolio or team, just replace "tile" with the desired custom post type key.


<?php

/**
 * Add author capabilities to Tile post type
 */
function custom_themify_cpt_add_author() {
	add_post_type_support( 'tile', 'author' );
}
add_action('init', 'custom_themify_cpt_add_author');

?>

Read More

New Contractor skin release. Use CONTRACTOR for 30% off regular memberships or $50 off Lifetime with code CONTRACTORLIFE