Oz Web Services
  • Home
  • WP
  • PHP
  • JS
  • CSS
  • SCSS
  • HTML
  • XML
  • JSON
  • SQL
  • .htaccess
  • Apache
  • Nginx
  • INI
  • HTTP
  • Diff
Search shortcode

Add IE Support for HTML5 Shiv

// Double check the src
function add_ie_html5_shim() {
	echo '<!–[if lt IE 9]>';
	echo '<script src=”http://html5shim.googlecode.com/svn/trunk/html5.js”></script>';
	echo '<![endif]–>';
}
if ($GLOBALS['is_IE']) {
	add_action('wp_head', 'add_ie_html5_shim');
}

Builder: Add DOM Element Before Container

// Add DOM element to Builder before container output (right after opening body tag)
function add_dom_element() {
	echo '<div class"custom-class></div>';
}
add_action('builder_layout_engine_render_container', 'add_dom_element' );

WP: add_role() remove_role()

// Only need to load a page once to get this into db, then comment out (or place in theme/plugin activation)
// WP Codex: http://codex.wordpress.org/Roles_and_Capabilities
$result = add_role(
	'basic_contributor',
	__( 'Basic Contributor' ),
	array(
		'read'         => true,  // true allows this capability
		'edit_posts'   => true,
		'delete_posts' => false, // Use false to explicitly deny
	)
);
if ( null !== $result ) {
	echo 'Yay! New role created!';
} else {
	echo 'Oh... the basic_contributor role already exists.';
}

// Or remove a role
remove_role( 'basic_contributor' );

WP: Shortcode

function callback( $atts, $content = '' ) {

	extract( shortcode_atts( array(
		'text'  => '',
		'link'  => '',
	), $atts ) );

	return '';
}
add_shortcode( 'name', 'callback' );

WP: Plugins: Get Custom Post Type Template

/**
 * get_template
 *
 * @since 0.1
 */
function get_custom_post_type_template( $template ) {
	global $post;
	if ( $post->post_type == 'my_post_type' ) {
		$template = dirname( __FILE__ ) . '/post-type-template.php';
	}
	return $template;
}
add_filter( 'template_include', 'get_custom_post_type_template' );

/* more filters (from http://codex.wordpress.org/Template_Hierarchy)
archive_template
author_template
category_template
tag_template
taxonomy_template
date_template
home_template
front_page_template
page_template
paged_template
search_template
single_template
attachment_template
*/

Builder: Add Classes to Modules

/**
 * Add classes to Builder modules
 *
 * Function name calling shouldn't be 'it_builder_loaded'
 * in case parent theme is using it already.
 */
if ( ! function_exists( 'oz_builder_loaded' ) ) {
function oz_builder_loaded() {
	// -->                          module        label                           class
	builder_register_module_style( 'content',    'Blue ',                        'content-blue' );
	builder_register_module_style( 'widget-bar', 'Blue (full width)',            'widget-bar-blue' );
	builder_register_module_style( 'navigation', 'Subnav Blue',                  'subnav-blue' );
	builder_register_module_style( 'html',       'Blue Background',              'html-blue' );
	builder_register_module_style( 'image',      'Blue Background (full width)', 'image-blue');
	builder_register_module_style( 'header',     'White Header',                 'header-white');
	builder_register_module_style( 'footer',     'White Footer',                 'footer-white');
}
add_action( 'it_libraries_loaded', 'oz_builder_loaded' );
}

Example: WP

define( 'DS', DIRECTORY_SEPARATOR );						// DIRECTORY_SEPARATOR
define( 'OZ_CONTENT_DIR', 'assets' );						//
define( 'WP_CONTENT_DIR', ABSPATH      .OZ_CONTENT_DIR );	// /svr-root/path-to/site-root/assets
define( 'WP_CONTENT_URL', WP_SITEURL.DS.OZ_CONTENT_DIR );	// http://site.dev/assets
define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR.DS.'plugins' );		// /svr-root/path-to/site-root/assets/plugins
define( 'WP_PLUGIN_URL', WP_CONTENT_URL.DS.'plugins' );		// http://site.dev/assets/plugins
define( 'UPLOADS',       OZ_CONTENT_DIR.DS.'files' );		// http://site.dev/assets/files
Oz Web Services
Copyright © 2015-2023 All Rights Reserved