In a current project I am using pages as templates, to load content into specific containers on the website. The website will be using up to 15 different languages.
The main language setup is done through WPML, which creates linked content per language. This helps, as some languages will fail terribly when translating them through a pure gettext setup, as the words setup is often completely different.
But there is always static stuff that can be translated directly through the language files. For that I use a simple shortcode that allows me to keep the native language as a basis in all linked content. Easier to move around, as I can actually read and understand it :)
Call the shortcode from the functions.php
1 |
add_shortcode('quick_trans','do_quick_trans'); |
The shortcode function itself. This loads the language textdomain from the specified location and translates the string.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
function do_quick_trans($atts, $content) { extract(shortcode_atts(array( 'location' => 'PATH_TO_LANG_FILE', 'lang' => 'LANG_TO_USE', 'textdomain' => 'TEXTDOMAIN' ), $atts)); load_textdomain($textdomain, $location.$lang.'.mo'); $content = __($content, $textdomain); return $content; } |
How to use it in your post or page content
1 2 3 4 5 6 7 8 |
German [quick_trans lang="de_DE"]Simple is nice![/quick_trans] Spanish [quick_trans lang="es_ES"]Simple is nice![/quick_trans] Spanish - Latin America / with a special path for the lang file location [quick_trans lang="es_LA" location="/wp-content/..."]Simple is nice![/quick_trans] |
Conditional Tags are a powerful thing in WordPress and especially handy to show or hide things.
„The Conditional Tags can be used in your Template files to change what content is displayed and how that content is displayed on a particular page depending on what conditions that page matches. “
Two plugins are part of my essentials, that utilize the Conditional Tags:
You can easily define your own Conditional Tags in your functions.php or plugin.
This time picker provides a unique way to enhance your input fields. Use a clock interface to enter the time. The plugin works with Bootstrap or standalone.
Part of my essentials :)
Datedropper is a jQuery Plugin that provides a quick and appealing interface to enter dates. Nice little plugin to spice up your interface.
Definitely part of my list of essentials :)
1 2 3 |
header('Cache-Control: no-cache, must-revalidate'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header('Content-type: application/json'); |
The first two headers prevent the browser from caching the response and the third sets the correct MIME type for JSON.
Than just output your JSON data
1 2 3 4 5 6 7 8 9 10 |
$data = array( "fire" => 1, "water" => 0, "earth" => 1, "air" => 1, ); echo json_encode($data); exit; |
„NextGEN Facebook (NGFB) gives you total control over the information social website crawlers need, improving Google Search ranking, social engagement, and click-through-rates on Facebook, Google+, Twitter, Pinterest, LinkedIn, StumbleUpon, Tumblr and and many more“
A powerful plugin for WordPress, but it sometimes displays many image dimension errors. Even if those errors remind me to optimize the page or post, I sometimes prefer to ignore these during development :)
Here a simple way to hide them:
1 2 3 4 5 6 7 |
add_action('admin_head', 'hide_ngfb_errors'); function hide_ngfb_errors(){ echo '<style type="text/css"> [id^="err_err_wp"]{display: none} </style>'; } |
When loading web-fonts, we often see a brief un-styled moment before the browser applies the actual font. Gladly Typekit and also Google Web Fonts provide an option around that.
Both are using WebFont Loaders to help handle those brief moments.
TypeKit Webfont Loader Example
1 2 3 4 5 6 7 |
(function(d) { var config = { kitId: '***' , // Your Kit ID scriptTimeout: 3000 }, h=d.documentElement,t=setTimeout(function(){h.className=h.className.replace(/\bwf-loading\b/g,"")+" wf-inactive";},config.scriptTimeout),tk=d.createElement("script"),f=false,s=d.getElementsByTagName("script")[0],a;h.className+=" wf-loading";tk.src='//use.typekit.net/'+config.kitId+'.js';tk.async=true;tk.onload=tk.onreadystatechange=function(){a=this.readyState;if(f||a&&a!="complete"&&a!="loaded")return;f=true;clearTimeout(t);try{Typekit.load(config)}catch(e){}};s.parentNode.insertBefore(tk,s) })(document); |
This adds a class name to the <html> element during loading
1 |
<html class="wf-loading"> |
This is removed when loading is done. This allows us to hide content until all fonts are loaded.
Webfonts Loading
1 2 3 |
.wf-loading * { opacity: 0; } |
This also adds classes once the webfonts have been loaded, which allows us to add some transitions to reveal the content again.
Webfonts Loaded
1 2 3 4 5 6 7 |
.wf-active *, .wf-inactive * { -webkit-transition: opacity 1s ease-out; -moz-transition: opacity 1s ease-out; -o-transition: opacity 1s ease-out; transition: opacity 1s ease-out; } |
One last thing. You should add the webfont loader early in your content, so that it can do its magic before anything else is being loaded.
Parent
1 2 3 4 5 |
var ParentView = Backbone.View.extend({ events: { 'click': 'onclick' } }); |
Child
1 2 3 4 5 6 7 8 |
var ChildView = ParentView.extend({ events: function(){ return _.extend({}, ParentView.prototype.events,{ 'click':'childClick', }); } }); |
Adding Metaboxes in WordPress to your admin areas normally involves 3 steps:
This can be done much easier using Custom Metaboxes and Fields for WordPress, which is a metabox, custom fields and forms library. The library provides a bunch of custom fields and also allows you to add your own easily. Much easier to build new Metaboxes fast!
List of field types included:
Simple example from the CMB2 Github page
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
if ( file_exists( __DIR__ . '/cmb2/init.php' ) ) { require_once __DIR__ . '/cmb2/init.php'; } elseif ( file_exists( __DIR__ . '/CMB2/init.php' ) ) { require_once __DIR__ . '/CMB2/init.php'; } add_action( 'cmb2_init', 'cmb2_sample_metaboxes' ); /** * Define the metabox and field configurations. */ function cmb2_sample_metaboxes() { // Start with an underscore to hide fields from custom fields list $prefix = '_yourprefix_'; /** * Initiate the metabox */ $cmb = new_cmb2_box( array( 'id' => 'test_metabox', 'title' => __( 'Test Metabox', 'cmb2' ), 'object_types' => array( 'page', ), // Post type 'context' => 'normal', 'priority' => 'high', 'show_names' => true, // Show field names on the left // 'cmb_styles' => false, // false to disable the CMB stylesheet // 'closed' => true, // Keep the metabox closed by default ) ); // Regular text field $cmb->add_field( array( 'name' => __( 'Test Text', 'cmb2' ), 'desc' => __( 'field description (optional)', 'cmb2' ), 'id' => $prefix . 'text', 'type' => 'text', 'show_on_cb' => 'cmb2_hide_if_no_cats', // function should return a bool value // 'sanitization_cb' => 'my_custom_sanitization', // custom sanitization callback parameter // 'escape_cb' => 'my_custom_escaping', // custom escaping callback parameter // 'on_front' => false, // Optionally designate a field to wp-admin only // 'repeatable' => true, ) ); } |