Automatisch icoontjes toevoegen aan links via CSS zonder class

Voorbeelden van iconsIcoontjes toevoegen aan links ziet er mooi uit en het is handig voor bezoekers die zien wat voor soort link het betreft, bijvoorbeeld een externe link, een PDF- of Word-bestand.

Dit kan door de link een class met een achtergrondafbeelding mee te geven.

HTML:
<a href="http://www.externelink.nl" class="extern">externe link</a>

CSS:
a.extern {
  padding-right: 15px;
  background: url(images/icon-link.gif) no-repeat center right;
}

Maar het kan ook automatisch, zonder toevoeging van een class.

In onderstaand voorbeeld ga ik uit van de website mijnwebsite.nl. Aan alle links wordt standaard een achtergondafbeelding voor een externe link gegeven.
Daarna wordt bij alle interne links (die beginnen met http://mijnwebsite of http://www.mijnwebsite of een interne link zijn) de achtergrondafbeelding verwijderd. Naar keuze kun je nu afbeeldingen toevoegen voor mail-links, of links naar PDF-, ODT, Word of bestanden met andere extensies.
De padding is afhankelijk van de grootte van de achtergrondafbeelding.

a { 
  padding-right: 15px; 
  background: url(images/icon-link.gif) no-repeat center right; 
}

a[href^="http://mijnwebsite"] { 
  padding-right: 0; 
  background: none;
}
a[href^="http://www.mijnwebsite"] { 
  padding-right: 0; 
  background: none; 
}
a[href^="#"] { 
  padding-right: 0; 
  background: none; 
}
a[href^="mailto"] { 
  padding-right: 15px; 
  background: url(images/icon-mail.gif) no-repeat center right; 
}
a[href$='.pdf'] { 
  padding-right: 15px; 
  background: url(images/icon_pdf.gif) no-repeat center right; 
}
a[href$='.PDF'] { 
  padding-right: 15px; background: url(images/icon_pdf.gif) no-repeat center right; 
}
a[href$='.doc'] { 
  padding-right: 15px; 
  background: url(images/icon_pdf.gif) no-repeat center right; 
}
a[href$='.DOC'] { 
  padding-right: 15px; 
  background: url(images/icon_pdf.gif) no-repeat center right; 
}

See it in action op iacobien.nl

Toegankelijke social media share buttons in WordPress

Hoe voeg je toegankelijke social media buttons toe aan je post of page in WordPress als je de bezoeker je bericht of pagina wilt laten delen op bijvoorbeeld Facebook, Twitter, LinkedIn of Google+? Deze vraag kreeg ik van Winy Schalke van Alva Design.

De meeste kant-en-klare buttons voor het toevoegen van Social Media buttons worden opgebouwd in Javascript. Maar als je alle fancy stuff weghaalt en stript tot de basis blijft er eigenlijk alleen een link met variabelen over. Dit is ook te maken in alleen HTML/PHP. De link wordt dan opgebouwd via een functie in PHP.

Basale opbouw van de links

Voor Facebook:

  • de link: http://www.facebook.com/sharer.php
  • variabelen:
    • t=titel
    • u=de url van de te delen pagina

Voor Twitter

  • de link: http://twitter.com/share
  • variabelen:
    • text=titel
    • url=de url van de te delen pagina

Voor LinkedIn

  • de link: http://www.linkedin.com/shareArticle?mini=true
  • variabelen:
    • t=titel
    • title=de url van de te delen pagina

Voor  Google+

Voorbeeldcode

Een simpel voorbeeld in PHP, die je in WordPress kwijt kunt in je functions.php van je thema:

/**
 * Accessible share buttons
 * Displays 4 social media buttons with a share link beneath the post content on pages and posts, except for the homepage
 * Works inside the loop
 * Images are stored in the theme /images directory
 * Rian Rietveld rrwd.nl June 2012
 * @notes beta version 0.1
 **/

function rrwd_share_buttons( $post_content ) {
	global $post;

	// on posts and pages, except for home, comment out if necessary
	if ( is_home() || is_front_page() ) return $post_content;

	// Sanatize and urlencode title and permalink for inclusion in share links
	$share_title = sanitize_title( get_the_title() );
	$share_title = urlencode( $share_title );
	$share_permalink = get_permalink();
	$share_permalink = urlencode( $share_permalink );

	// Hidden heading, for screen readers only
	$share  = '<h2 class="rrwd-share-heading">Deze pagina delen</h2>'."\n";

        $share .= '<ul class="rrwd-share-list">'."\n";

        $share .= '<!--Facebook-->'."\n";
        $share .= '<li><a href="http://www.facebook.com/sharer.php?t=' . $share_title . '&amp;u=' . $share_permalink . '" rel="nofollow"><img src="' . get_bloginfo('stylesheet_directory') . '/images/share-facebook.png" alt="Delen op Facebook" class="rrwd-share-img" /></a></li>'."\n";

        $share .= '<!--Twitter-->'."\n";
$share .= '<li><a href="http://twitter.com/share?text=' . $share_title . '&amp;url=' . $share_permalink . '" rel="nofollow"><img src="' . get_bloginfo('stylesheet_directory') . '/images/share-twitter.png" alt="Delen op Twitter" class="rrwd-share-img"/></a></li>'."\n";
        $share .= '<!--Linkedin-->'."\n";
$share .= '<li><a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=' . get_permalink() . '&amp;title=' . $share_title . '" rel="nofollow"><img src="' . get_bloginfo('stylesheet_directory') . '/images/share-linkedin.png" alt="Delen op LinkedIn" class="rrwd-share-img" /></a></li>'."\n";
        $share .= '<!--Google plus-->'."\n";
$share .= '<li><a href="https://plus.google.com/share?url=' . get_permalink() . '" rel="nofollow"><img src="' . get_bloginfo('stylesheet_directory') . '/images/share-googleplus.png" alt="Delen op Google+" class="rrwd-share-img" /></a></li>'."\n";
        $share .= '</ul> '."\n";
        // add buttons beneath the post content
        $post_content .= $share;

        return $post_content;

} // end function rrwd_share_buttons

add_filter('the_content', 'rrwd_share_buttons');

CSS voor de buttons

In de style.php van je thema


/*Style for accessible share buttons
------------------------------------------------------------ */
.rrwd-share-heading {
	left: -1000em;
	position: absolute;
	height: 0;
}
.rrwd-share-list {
	clear: both;
}
.rrwd-share-list li {
	float: left;
	padding: 0;
	margin-right: 10px;
}

.rrwd-share-img {
	width: 55px;
	height: 20px;
}

De afbeeldingen

Zet de bijbehorende afbeeldingen in de directory /images van je thema.

De namen in deze functie zijn:

  • share-facebook.png
  • share-twitter.png
  • share-linkedin.png
  • share-googleplus.png

De afbeeldingen hebben dezelfde grootte, te stylen via de class rrwd-share-img.

Live demo

Winy Schalke heeft de code geïmplementeerd voor pagina’s en berichten van de website van de Epilepsie Vereniging Nederland

Plugin

Ik heb er een korte plugin van gemaakt.
Te downloaden op: http://www.rrwd.nl/wp-plugins/wp-accessible-social-share-buttons.zip
Als je deze upload en activeert en daarna in je functions.php van je childtheme het volgende zet zou het moeten lukken:

In Genesis onder de titel:

add_action( 'genesis_after_post_title', 'wp_accessible_social_share_buttons' );// adds buttons below the title of a post or page

Voor plaatsing onder de content:

add_action('the_content', 'wp_accessible_social_share_buttons'); // adds buttons below the content of a post or page

Discussie

De links in deze functie openen niet in een nieuw venster. Dit kan worden toegevoegd (zet dan in de link target=”_blank”) mits je hiervan melding maakt, zie de webrichtlijnen hierover.

Gebruik voor de & om variabelen te linken een &amp;

Documentatie

Code snippits voor het Genesis Framework in WordPress

Doctype HTML5

/** HTML5 DOCTYPE */
remove_action( 'genesis_doctype', 'genesis_do_doctype' );
add_action( 'genesis_doctype', 'child_do_doctype' );
function child_do_doctype() {
?>
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head >
<meta http-equiv="Content-Type" content="<?php bloginfo( 'html_type' ); ?>; charset=<?php bloginfo( 'charset' ); ?>" />
<?php
}

Pas knoppenbalk TinyMCE aan

/** Modifying TinyMCE editor to remove unused items.

http://wordpress.org/support/topic/tinymce-formatting-options-remove-h1-h1-pre/


http://wordpress.org/support/profile/buckmuck

*/
function rrwd_customformat_tinymce($init) {
// Add block format elements you want to show in dropdown
$init['theme_advanced_blockformats'] = 'p,h2,h3,pre';
$init['theme_advanced_disable'] = 'strikethrough,underline,forecolor,justifyfull';
return $init;
}
add_filter('tiny_mce_before_init', 'rrwd_customformat_tinymce' );

Gebruik een eigen stylesheet in TinyMCE

Zo kun je elementen van het stylesheet overnemen in de editor zodat het lijkt op de weergave in de website zelf. Het bestand editor-style.css zet je dan in je (child-)theme.

add_editor_style( 'editor-style.css' );

Verwijder layout keuzes: bijvoorbeeld

genesis_unregister_layout( 'content-sidebar' );
genesis_unregister_layout( 'content-sidebar-sidebar' );
genesis_unregister_layout( 'sidebar-sidebar-content' );
genesis_unregister_layout( 'sidebar-content-sidebar' );
genesis_unregister_layout( 'full-width-content' );

Custom Favicon (in plaats van het Genesis icoontje)

/** Custom Favicon
The favicon is stored in the theme/images directory and is called favicon.ico by default*/
remove_action('genesis_meta', 'genesis_load_favicon');
function rrwd_custom_favicon() {
echo "<link rel='shortcut icon' href='".get_stylesheet_directory_uri()."/images/favicon.ico' />\n";
}
add_action('wp_head', 'rrwd_custom_favicon');

Bepaal het aantal sidebars in de footer

/** Add support for 1-column footer widgets */
add_theme_support( 'genesis-footer-widgets', 1 );

Pas de copyright regel aan in de footer

/** Customize the credits */
add_filter('genesis_footer_creds_text', 'custom_footer_creds_text');
function custom_footer_creds_text() {
 echo '<div class="creds"><p>';
 echo 'Copyright &copy; ';
 echo date('Y');
 echo ' &middot; Claudia Hulshof, Sustainable Style';
 echo '</p></div>';
}

Verwijder de hele footer

/** Customize the entire footer */
remove_action( 'genesis_footer', 'genesis_do_footer' );

Verwijder de (bewerken) link op de website zelf als een gebruiker is ingelogd.

/** Remove the edit linkon the front end */
add_filter ( 'genesis_edit_post_link' , '__return_false' );

Meer op:

How accessible is the WordPress CMS for a blind content manager

As we take great effort to make the front-end of WordPress accessible, the next challenge will be to make an equally accessible CMS. In order to get an impression on this challenge awaiting us I have started a study, together with Jaap van de Putte on how accessible the current CMS of WordPress really is.

A few questions immediately come to mind. During the last couple of years the CMS of WordPress has become more and more dependent on Ajax with lightbox overlays. How do these function for a blind content manager using a screenreader? Can she/he grasp the complexity of the CSM? Is the generated HTML semantically correct and easy to understand?

In my experience as WordPress trainer I have found that the CMS is getting harder to understand for inexperienced content managers. So many options and possibilities. How does this work, if you look thought the CMS pages sequencially, without a quick overview that the graphics provide?

What better way to find out, then to visit a experienced vision-impaired user of computers and screen readers that never ever saw a CMS in his life. Actually, this is not that much unlike most of my seeing clients who want a website and a CMS.

For this I visited Leo Dijk, who works as a legal advisor at the Dutch Ministry of Education, Culture and Science in The Hague. He was kind enough to give me a morning of his time to try out the current CMS of WordPress.

Used software

At this moment there are two major screenreaders: SuperNova by Dolphin and Jaws by Freedom Scientific. Leo uses Explorer 8 with the SuperNova Screenreader version 11.58 on Windows, together with a braille terminal, a standard keyboard and a headphone. This is neither the latest version of Explorer nor the latest version SuperNova, but it is a common configuration for most blind people, especially as updates of SuperNova are expensive. This version of SuperNova doesn’t work well with Explorer 9, nor with Firefox, nor with Chrome. Javascript is executed, however.

WordPress test environment

In my test account I installed Dutch version of WordPress 3.3.1 with the StudioPress Genesis Framework with one extra plugin: Genesis Translations by Remkus de Vries. All settings and options out of the box. To get started some dummy content and a primary menu was added.

Front end experience

For reading the content and structure the front end was good. Tab order was logical and Leo gave StudioPress a compliment about how well the search widget was setup. There where however two important remarks:

  1. Widget titles in Genesis by default have the H4 HTML tag. The content will contain mainly H1 and H2 levels, so an H4 skips the H3 level. This makes the structure of the information less accessible. A H2 for the widget title would be better.
  2. In WordPress images default link to their own image when inserted into content. So, if clicked, the visible window will only contain a single image, and the site only can be recovered by using the back button. A normally sighted visitor can see what is happening and solve it intuitively. But, with a screen reader it is not so obvious. Leo couldn’t interpret what happened and concluded it was a broken link, because neither the title nor the alt tag of the images told him he was clicking a link to an image.

CMS

For normally sighted and visually impaired content managers, the first impression of the CMS is confusing. Much info, what does the jargon mean. As for everybody else an explanation was needed about the difference between a post and a page, the menu-item links, etc.

Tab en item order

With a screen reader, the page is read from top to bottom. The tab key is used to skip from item to item. An easy way to see what the resulting page order is like, is to disable the CSS.

WordPress menu with stylesheet disabled

WordPress menu with stylesheet disabled

The semantics of the HTML for adding a post

  • Main Menu (for the Genesis theme there is an extra link with only the image)
  • Adjust screen, help e.g.
  • Title of the action
  • Publish options
  • Categories
  • Tags
  • Features image
  • Input title
  • Input content
  • Theme SEO (Genesis theme)
  • Layout (Genesis theme)
  • Excerpt
  • Trackbacks
  • Custom fields
  • Comments
  • Slug Author

Menu

A problem for the screenreader user is that the reader could not determine the structure of the list items. What is a main menu item and what a subitem? The reason is that the subitems are placed into separate div’s and not directly into tags relating to their list.

<li class="wp-has-submenu wp-not-current-submenu menu-top menu-icon-users" id="menu-users">
 <div class='wp-menu-image'><a href='users.php'><br />
 </a></div>
 <div class="wp-menu-arrow">
 <div></div>
 </div>
 <a href='users.php' class="wp-has-submenu wp-not-current-submenu menu-top menu-icon-users" tabindex="1" aria-haspopup="true">Gebruikers</a>
 <div class='wp-submenu'>
 <div class='wp-submenu-wrap'>
 <div class='wp-submenu-head'>Gebruikers</div>
 <ul>
 <li class="wp-first-item"><a href='users.php' class="wp-first-item" tabindex="1">Alle gebruikers</a></li>
 <li><a href='user-new.php' tabindex="1">Nieuwe toevoegen</a></li>
 <li><a href='profile.php' tabindex="1">Je profiel</a></li>
 </ul>
 </div>
 </div>
</li>

Finding the title input field

The label of the title is placed inside the input field for the title with CSS and Javascript. Hidden without Javascript and with a default style of  visibility:hidden. In practice this means that with a screenreader the label is completely ommited.

<div id="titlewrap">
<label class="hide-if-no-js"  style="visibility:hidden" id="title-prompt-text" for="title">Voer hier de titel in</label>
<input type="text" name="post_title" size="30" tabindex="1" value="" id="title" autocomplete="off" />
</div>

Finding the content textarea

Using the WYSIWYG editor is obviously impossible. Selecting some text and changing it into a heading for instance is a task that cannot be done with a screen reader. Therefore the default setting must be to use the HTML editor or an editor that uses shortcodes for text markup.

The content text-area also lacks a label and can only be found by searching for the text “uploaden/toevoegen”  (Upload/Add) which is just above the input area.

<div id="wp-content-wrap"><link rel='stylesheet' id='editor-buttons-css'  href='http://rrwd-demo.nl/wp-includes/css/editor-buttons.css?ver=20111114' type='text/css' media='all' />
<div id="wp-content-editor-tools"><a id="content-html" onclick="switchEditors.switchto(this);">HTML</a>
<a id="content-tmce" onclick="switchEditors.switchto(this);">Wysiwyg</a>
<div id="wp-content-media-buttons"><a href="http://rrwd-demo.nl/wp-admin/media-upload.php?post_id=715&TB_iframe=1" id="content-add_media" title="Media toevoegen" onclick="return false;">Uploaden/Toevoegen <img src="http://rrwd-demo.nl/wp-admin/images/media-button.png?ver=20111005" width="15" height="15" /></a></div>
</div>
<div id="wp-content-editor-container"><textarea rows="20" tabindex="1" cols="40" name="content" id="content"></textarea></div>
</div>

Popup overlay’s

Adding links, inserting images, choosing colours, all work with through pop-ups that break out of the normal flow of the HTML and are not recognised as a popup in a screenreader, they are simply ignored.

Adding media

Inline addition of media with the upload/add option is impossible for a screenreader. But it can be achieved manually, using the menu-item ‘media’ first for uploading images and document and subsequently adding them later via the HTML code.

Conclusion and recommendations

The main issues are:

  • The input field for the title and the content are currently unrecognizable, they need a label and not just one inside the inputfield
  • The content manager will need to know HTML, since the buttons for the HTML markup don’t work in a screenreader.
  • The semantics of the HTML produced can be improved.

How to make life easier for a blind content manager:

  • Change the HTML into a more semantic order like
    • the main menu
    • input for the title
    • input for the content
    • publish options
    • the sidebar with the extra options
    • the help and adjust screen options
  • Add a label to the title and content input
  • Find a decent shortcode editor te replace the WYSIWYG, plugin suggestions are welcome.

Next step

This test was done using SuperNova by Dolphin. We will look into how Jaws performs in another session.
More idea’s, input, comments and suggestions for e.g. plugins are very welcome.

Thanks

A big thanks to Leo Dijk, for his detemination, patience and enthousiasm.

Menu titel laten zien boven uitvoer wp_nav_menu van WordPress

In WordPress kun je eigen menu’s samenstellen en via de functie wp_nav_menu weergeven. Helaas zit er (nog?) geen optie bij om ook de titel van het menu te laten zien. Hieronder een manier om de titel op te halen en boven het menu te zetten.

Vervang onderstaand voorbeeld het id 9 door het id van het menu dat je wilt gebruiken.

In functions.php

function rrwd_get_name_menu ($id_menu) {
	// thanks to Pranick, http://themeforest.net/forums/thread/help-wp-nav-menu-title/45109?page=1
	$cippo_menu_locations = (array) get_nav_menu_locations();
	$cippo_menu = get_term_by( 'id', $id_menu, 'nav_menu', ARRAY_A );
	echo $cippo_menu[ 'name' ];
}

In de template bijvoorbeeld

<h2><?php rrwd_get_name_menu(9); ?></h2>
<?php wp_nav_menu( array( 'container_class' => 'menu-header', 'menu' => 9) ); ?>

Code-snippit: submenu in WordPress

Deze code laat (buiten de loop) een submenu zien van een pagina met kinders in WordPress

<?php  
if($post->post_parent) {  
  $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0&sort_column=menu_order");  
  $titlenamer = get_the_title($post->post_parent);  
} else {  
  $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0&sort_column=menu_order");  
  $titlenamer = get_the_title($post->ID);  
}  
if ($children) { ?>
  <h2> <? echo $titlenamer ?> </h2>  
  <ul id="sidebar-menu">    
    <?php echo $children; ?>  
  </ul>
<?php } ?>

See it in action: Regelink.net

Bron: WordPress forum

ideal

Using Gravity Forms for iDeal payment

IDEAL is an on-line payment method, populair in the Netherlands and Belgium. For the integration of iDEAL Light  into WordPress, I used the outstanding plugin Gravity Forms (GF), in combination with 2 new template files. This is my first attempt, feel free to notify me of better ways to do stuff. I used GF version 1.4.5 for this. The next version of GF has more options for payment, but well, this works for now ;) . Lees verder

Geen sifr, geen cufon maar Font-face!

De laatste bijdrage van onze (nu ex-)stagiaire Rick Leyten: Na de fijne ervaring met sifr *ahum* besloot ik om te gaan zoeken naar een vervanging en die vond ik!
De makers van font-face maken het zo makkelijk dat echt het geen flash nodig heeft om te functioneren. Sterker nog iedereen met een geupdate browser (op Opera na.. dit komt binnenkort) ziet deze fonts. Lees verder

grafityforms

Gravity Form met een dynamische input

Voor een project bij RRWD web development, moest ik een functionaliteit bedenken i.v.m. het ontwerp van een nieuwe WordPress website. In dit grafisch ontwerp stond in de sidebar een drop down menu met een submit button. Je kunt in dit geval een afspraak maken en alvast aangeven waar het over gaat. Dus zou het mooi zijn als de aangegeven reden van afspraak onthouden zou worden en meegestuurd werd naar het afspraak-formulier. Dit staat niet standaard in Gravity Forms, dus moest ik uit zoeken hoe we dit voor elkaar krijgen. Lees verder