SlideShare une entreprise Scribd logo
1  sur  14
Coolfields Consulting www.coolfields.co.uk
@coolfields
Obscure WordPress Functions
that are actually quite useful…
Graham Armfield
Web Accessibility Consultant
WordPress Developer
graham.armfield@coolfields.co.uk
@coolfields
Obscure? Really?
Well, maybe not known to everyone…
2
Formatting text
wpautop($str);
• Adds in line breaks and paragraphs
• Useful for printing textarea custom fields
3
Formatting text
But… sometimes wpautop() goes too far
• Adds in empty paragraphs
• <div> elements in paragraphs
• Often happens when using shortcodes
• Can be down to the order that things get done
4
Removing empty paragraphs
remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'wpautop' , 99);
function remove_empty_p($content){
$content = force_balance_tags($content);
return
preg_replace('#<p>s*+(<brs*/*>)?s*</p>#i',
'', $content);
}
add_filter('the_content', 'remove_empty_p', 20, 1);
5
More on shortcodes
Allow shortcodes to be interpreted in widgets:
add_filter('widget_text', 'do_shortcode');
Remove all shortcodes from a string:
strip_shortcodes( $content );
6
Excerpts
The default length is 55 words.
You can change this…
function custom_excerpt_length( $length ) {
return 30;
}
add_filter( 'excerpt_length',
custom_excerpt_length', 999 );
7
Localizing dates
Post/page published dates get localized
automatically by WP when site's language changes.
But, what if you have to set date formats in PHP?
8
Localizing dates
Eg: Custom fields may have date in database
format: 2016-02-25
This is useful for sorting, and selecting using
wp_query();
You may need to output: 25 Chwefror 2016
9
Localizing dates
Setting the locale in PHP can be a pain.
So use the WordPress capability instead –
date_i18n($pattern, $timestamp);
10
Localizing dates
function db_date_format($str_date, $pattern = ''){
// incoming format = yyyy-mm-dd
if (empty($pattern)) {
$pattern = get_option( 'date_format' );
}
$time_stamp = mktime(0,0,0,substr($str_date,5,2),
substr ($str_date,8,2),substr($str_date,0,4));
return date_i18n( $pattern, $time_stamp );
}
11
Pagination
On blog index pages, using
previous_posts_link() and
next_posts_link() is OK…
But it doesn't give site visitors an indication of how
many blog posts there are altogether.
Pagination may give better usability…
12
Pagination
global $wp_query;
if ($wp_query->max_num_pages > 1) {
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link($big) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages,
'end_size' => 3,
'type' => 'list',
'prev_text' => '&laquo; Newer<span class="srdr"> posts</span>',
'next_text' => 'Older<span class="srdr"> posts</span> &raquo;',
'before_page_number' => '<span class="srdr">Page </span>',
'after_page_number' => ''
) );
}
Can use this with custom queries too.
13
Thanks for listening
graham.armfield@coolfields.co.uk
@coolfields
14

Contenu connexe

Tendances

Distributed work with Gearman
Distributed work with GearmanDistributed work with Gearman
Distributed work with GearmanDominik Jungowski
 
言語の設計判断
言語の設計判断言語の設計判断
言語の設計判断nishio
 
AST + Better Reflection (PHP Benelux 2016 Unconference)
AST + Better Reflection (PHP Benelux 2016 Unconference)AST + Better Reflection (PHP Benelux 2016 Unconference)
AST + Better Reflection (PHP Benelux 2016 Unconference)James Titcumb
 
Maintaining your own branch of Drupal core
Maintaining your own branch of Drupal coreMaintaining your own branch of Drupal core
Maintaining your own branch of Drupal coredrumm
 
Mojolicious - A new hope
Mojolicious - A new hopeMojolicious - A new hope
Mojolicious - A new hopeMarcus Ramberg
 

Tendances (7)

Distributed work with Gearman
Distributed work with GearmanDistributed work with Gearman
Distributed work with Gearman
 
Mojolicious on Steroids
Mojolicious on SteroidsMojolicious on Steroids
Mojolicious on Steroids
 
言語の設計判断
言語の設計判断言語の設計判断
言語の設計判断
 
Views&urls
Views&urlsViews&urls
Views&urls
 
AST + Better Reflection (PHP Benelux 2016 Unconference)
AST + Better Reflection (PHP Benelux 2016 Unconference)AST + Better Reflection (PHP Benelux 2016 Unconference)
AST + Better Reflection (PHP Benelux 2016 Unconference)
 
Maintaining your own branch of Drupal core
Maintaining your own branch of Drupal coreMaintaining your own branch of Drupal core
Maintaining your own branch of Drupal core
 
Mojolicious - A new hope
Mojolicious - A new hopeMojolicious - A new hope
Mojolicious - A new hope
 

En vedette

Wordpress and Web Accessibility Wordcamp UK 2014
Wordpress and Web Accessibility Wordcamp UK 2014Wordpress and Web Accessibility Wordcamp UK 2014
Wordpress and Web Accessibility Wordcamp UK 2014Graham Armfield
 
Early Adopters to Participatory Professional Development
Early Adopters to Participatory Professional DevelopmentEarly Adopters to Participatory Professional Development
Early Adopters to Participatory Professional DevelopmentVanessa Vartabedian
 
Can WordPress help make the web more accessible - eaccess15 - Feb 2015
Can WordPress help make the web more accessible - eaccess15 - Feb 2015Can WordPress help make the web more accessible - eaccess15 - Feb 2015
Can WordPress help make the web more accessible - eaccess15 - Feb 2015Graham Armfield
 
Harnessing Themes, Plugins and Features to Make WordPress More Accessible
Harnessing Themes, Plugins and Features to Make WordPress More AccessibleHarnessing Themes, Plugins and Features to Make WordPress More Accessible
Harnessing Themes, Plugins and Features to Make WordPress More AccessibleGraham Armfield
 
Myers Dill and Sam Digirolamo Presentation
Myers Dill and Sam Digirolamo PresentationMyers Dill and Sam Digirolamo Presentation
Myers Dill and Sam Digirolamo PresentationBronwen Elizabeth Madden
 
So What is This Thing Called WordPress?
So What is This Thing Called WordPress?So What is This Thing Called WordPress?
So What is This Thing Called WordPress?Graham Armfield
 
N tier architecture
N tier architectureN tier architecture
N tier architectureNidhi Saurav
 
Byron Pojol IT Architect
Byron Pojol IT ArchitectByron Pojol IT Architect
Byron Pojol IT ArchitectByron Pojol
 
CHECKPOINT 2009: Agenturpräsentation von PLEON
CHECKPOINT 2009: Agenturpräsentation von PLEONCHECKPOINT 2009: Agenturpräsentation von PLEON
CHECKPOINT 2009: Agenturpräsentation von PLEONpolisphere
 
The Dark Side of Online Participation (AoIR 2016 talk)
The Dark Side of Online Participation (AoIR 2016 talk)The Dark Side of Online Participation (AoIR 2016 talk)
The Dark Side of Online Participation (AoIR 2016 talk)Christoph Lutz
 
Inclusive Design From Approach to Execution
Inclusive Design From Approach to ExecutionInclusive Design From Approach to Execution
Inclusive Design From Approach to ExecutionCorey Timpson
 
Content Marketing - Präsentation Online Marketing Forum
Content Marketing - Präsentation Online Marketing ForumContent Marketing - Präsentation Online Marketing Forum
Content Marketing - Präsentation Online Marketing ForumScribbleLive
 
Emerging Technologies, Emerging Perspectives on Education, and Cultures of Sh...
Emerging Technologies, Emerging Perspectives on Education, and Cultures of Sh...Emerging Technologies, Emerging Perspectives on Education, and Cultures of Sh...
Emerging Technologies, Emerging Perspectives on Education, and Cultures of Sh...George Veletsianos
 

En vedette (15)

Synergy Marketing Corp.
Synergy Marketing Corp.Synergy Marketing Corp.
Synergy Marketing Corp.
 
Wordpress and Web Accessibility Wordcamp UK 2014
Wordpress and Web Accessibility Wordcamp UK 2014Wordpress and Web Accessibility Wordcamp UK 2014
Wordpress and Web Accessibility Wordcamp UK 2014
 
Early Adopters to Participatory Professional Development
Early Adopters to Participatory Professional DevelopmentEarly Adopters to Participatory Professional Development
Early Adopters to Participatory Professional Development
 
Can WordPress help make the web more accessible - eaccess15 - Feb 2015
Can WordPress help make the web more accessible - eaccess15 - Feb 2015Can WordPress help make the web more accessible - eaccess15 - Feb 2015
Can WordPress help make the web more accessible - eaccess15 - Feb 2015
 
Harnessing Themes, Plugins and Features to Make WordPress More Accessible
Harnessing Themes, Plugins and Features to Make WordPress More AccessibleHarnessing Themes, Plugins and Features to Make WordPress More Accessible
Harnessing Themes, Plugins and Features to Make WordPress More Accessible
 
Myers Dill and Sam Digirolamo Presentation
Myers Dill and Sam Digirolamo PresentationMyers Dill and Sam Digirolamo Presentation
Myers Dill and Sam Digirolamo Presentation
 
So What is This Thing Called WordPress?
So What is This Thing Called WordPress?So What is This Thing Called WordPress?
So What is This Thing Called WordPress?
 
N tier architecture
N tier architectureN tier architecture
N tier architecture
 
Byron Pojol IT Architect
Byron Pojol IT ArchitectByron Pojol IT Architect
Byron Pojol IT Architect
 
CHECKPOINT 2009: Agenturpräsentation von PLEON
CHECKPOINT 2009: Agenturpräsentation von PLEONCHECKPOINT 2009: Agenturpräsentation von PLEON
CHECKPOINT 2009: Agenturpräsentation von PLEON
 
The Dark Side of Online Participation (AoIR 2016 talk)
The Dark Side of Online Participation (AoIR 2016 talk)The Dark Side of Online Participation (AoIR 2016 talk)
The Dark Side of Online Participation (AoIR 2016 talk)
 
Inclusive Design From Approach to Execution
Inclusive Design From Approach to ExecutionInclusive Design From Approach to Execution
Inclusive Design From Approach to Execution
 
Cutting edge Essbase
Cutting edge EssbaseCutting edge Essbase
Cutting edge Essbase
 
Content Marketing - Präsentation Online Marketing Forum
Content Marketing - Präsentation Online Marketing ForumContent Marketing - Präsentation Online Marketing Forum
Content Marketing - Präsentation Online Marketing Forum
 
Emerging Technologies, Emerging Perspectives on Education, and Cultures of Sh...
Emerging Technologies, Emerging Perspectives on Education, and Cultures of Sh...Emerging Technologies, Emerging Perspectives on Education, and Cultures of Sh...
Emerging Technologies, Emerging Perspectives on Education, and Cultures of Sh...
 

Similaire à Obscure Wordpress Functions That Are Actually Quite Useful

Advanced and Hidden WordPress APIs
Advanced and Hidden WordPress APIsAdvanced and Hidden WordPress APIs
Advanced and Hidden WordPress APIsandrewnacin
 
Becoming a better WordPress Developer
Becoming a better WordPress DeveloperBecoming a better WordPress Developer
Becoming a better WordPress DeveloperJoey Kudish
 
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Mike Schinkel
 
Tidy Up Your Code
Tidy Up Your CodeTidy Up Your Code
Tidy Up Your CodeAbbas Ali
 
[WLDN] Supercharging word press development in 2018
[WLDN] Supercharging word press development in 2018[WLDN] Supercharging word press development in 2018
[WLDN] Supercharging word press development in 2018Adam Tomat
 
Advanced Drupal Views: Theming your View
Advanced Drupal Views: Theming your ViewAdvanced Drupal Views: Theming your View
Advanced Drupal Views: Theming your ViewRyan Cross
 
What's new in the Drupal 7 API?
What's new in the Drupal 7 API?What's new in the Drupal 7 API?
What's new in the Drupal 7 API?Alexandru Badiu
 
Why is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenariosWhy is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenariosDivante
 
Laying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme developmentLaying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme developmentTammy Hart
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)arcware
 
Wordcamp Fayetteville Pods Presentation (PDF)
Wordcamp Fayetteville Pods Presentation (PDF)Wordcamp Fayetteville Pods Presentation (PDF)
Wordcamp Fayetteville Pods Presentation (PDF)mpvanwinkle
 
Custom post-framworks
Custom post-framworksCustom post-framworks
Custom post-framworkswcto2017
 
Custom post-framworks
Custom post-framworksCustom post-framworks
Custom post-framworksKiera Howe
 
You Don't Know Query (WordCamp Netherlands 2012)
You Don't Know Query (WordCamp Netherlands 2012)You Don't Know Query (WordCamp Netherlands 2012)
You Don't Know Query (WordCamp Netherlands 2012)andrewnacin
 
[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress DevelopmentAdam Tomat
 
You don’t know query - WordCamp UK Edinburgh 2012
You don’t know query - WordCamp UK Edinburgh 2012You don’t know query - WordCamp UK Edinburgh 2012
You don’t know query - WordCamp UK Edinburgh 2012l3rady
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkDirk Haun
 
WebCamp: Developer Day: DDD in PHP on example of Symfony - Олег Зинченко
WebCamp: Developer Day: DDD in PHP on example of Symfony - Олег ЗинченкоWebCamp: Developer Day: DDD in PHP on example of Symfony - Олег Зинченко
WebCamp: Developer Day: DDD in PHP on example of Symfony - Олег ЗинченкоGeeksLab Odessa
 
Drupal Module Development - OSI Days 2010
Drupal Module Development - OSI Days 2010Drupal Module Development - OSI Days 2010
Drupal Module Development - OSI Days 2010Siva Epari
 

Similaire à Obscure Wordpress Functions That Are Actually Quite Useful (20)

Advanced and Hidden WordPress APIs
Advanced and Hidden WordPress APIsAdvanced and Hidden WordPress APIs
Advanced and Hidden WordPress APIs
 
Becoming a better WordPress Developer
Becoming a better WordPress DeveloperBecoming a better WordPress Developer
Becoming a better WordPress Developer
 
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
 
Tidy Up Your Code
Tidy Up Your CodeTidy Up Your Code
Tidy Up Your Code
 
[WLDN] Supercharging word press development in 2018
[WLDN] Supercharging word press development in 2018[WLDN] Supercharging word press development in 2018
[WLDN] Supercharging word press development in 2018
 
Advanced Drupal Views: Theming your View
Advanced Drupal Views: Theming your ViewAdvanced Drupal Views: Theming your View
Advanced Drupal Views: Theming your View
 
What's new in the Drupal 7 API?
What's new in the Drupal 7 API?What's new in the Drupal 7 API?
What's new in the Drupal 7 API?
 
WordCamp Praga 2015
WordCamp Praga 2015WordCamp Praga 2015
WordCamp Praga 2015
 
Why is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenariosWhy is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenarios
 
Laying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme developmentLaying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme development
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
 
Wordcamp Fayetteville Pods Presentation (PDF)
Wordcamp Fayetteville Pods Presentation (PDF)Wordcamp Fayetteville Pods Presentation (PDF)
Wordcamp Fayetteville Pods Presentation (PDF)
 
Custom post-framworks
Custom post-framworksCustom post-framworks
Custom post-framworks
 
Custom post-framworks
Custom post-framworksCustom post-framworks
Custom post-framworks
 
You Don't Know Query (WordCamp Netherlands 2012)
You Don't Know Query (WordCamp Netherlands 2012)You Don't Know Query (WordCamp Netherlands 2012)
You Don't Know Query (WordCamp Netherlands 2012)
 
[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development
 
You don’t know query - WordCamp UK Edinburgh 2012
You don’t know query - WordCamp UK Edinburgh 2012You don’t know query - WordCamp UK Edinburgh 2012
You don’t know query - WordCamp UK Edinburgh 2012
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application Framework
 
WebCamp: Developer Day: DDD in PHP on example of Symfony - Олег Зинченко
WebCamp: Developer Day: DDD in PHP on example of Symfony - Олег ЗинченкоWebCamp: Developer Day: DDD in PHP on example of Symfony - Олег Зинченко
WebCamp: Developer Day: DDD in PHP on example of Symfony - Олег Зинченко
 
Drupal Module Development - OSI Days 2010
Drupal Module Development - OSI Days 2010Drupal Module Development - OSI Days 2010
Drupal Module Development - OSI Days 2010
 

Plus de Graham Armfield

Useful Accessibility Tools Version 3 - Jul 2021
Useful Accessibility Tools Version 3 - Jul 2021Useful Accessibility Tools Version 3 - Jul 2021
Useful Accessibility Tools Version 3 - Jul 2021Graham Armfield
 
So how do i know if my wordpress website is accessible - WordPress Accessibil...
So how do i know if my wordpress website is accessible - WordPress Accessibil...So how do i know if my wordpress website is accessible - WordPress Accessibil...
So how do i know if my wordpress website is accessible - WordPress Accessibil...Graham Armfield
 
Useful Accessibility Tools - WordCamp Brighton
Useful Accessibility Tools - WordCamp BrightonUseful Accessibility Tools - WordCamp Brighton
Useful Accessibility Tools - WordCamp BrightonGraham Armfield
 
Accessibility Hacks Version 2
Accessibility Hacks Version 2Accessibility Hacks Version 2
Accessibility Hacks Version 2Graham Armfield
 
Accessibility Hacks version 2
Accessibility Hacks version 2Accessibility Hacks version 2
Accessibility Hacks version 2Graham Armfield
 
Useful Accessibility Tools - WP Pompey April 2019
Useful Accessibility Tools - WP Pompey April 2019Useful Accessibility Tools - WP Pompey April 2019
Useful Accessibility Tools - WP Pompey April 2019Graham Armfield
 
How to Build an Accessible WordPress Theme
How to Build an Accessible WordPress ThemeHow to Build an Accessible WordPress Theme
How to Build an Accessible WordPress ThemeGraham Armfield
 
Accessibility Hacks Wordcamp Manchester October 2018
Accessibility Hacks Wordcamp Manchester October 2018Accessibility Hacks Wordcamp Manchester October 2018
Accessibility Hacks Wordcamp Manchester October 2018Graham Armfield
 
Useful Accessibility Tools
Useful Accessibility ToolsUseful Accessibility Tools
Useful Accessibility ToolsGraham Armfield
 
Assistive technology Demo WordCamp Bristol
Assistive technology Demo WordCamp BristolAssistive technology Demo WordCamp Bristol
Assistive technology Demo WordCamp BristolGraham Armfield
 
Designing for Accessibility - WordCamp London 2017
Designing for Accessibility - WordCamp London 2017Designing for Accessibility - WordCamp London 2017
Designing for Accessibility - WordCamp London 2017Graham Armfield
 
Designing for Accessibility - Front End North - September 2016
Designing for Accessibility - Front End North - September 2016Designing for Accessibility - Front End North - September 2016
Designing for Accessibility - Front End North - September 2016Graham Armfield
 
Themes Plugins and Accessibility - WordCamp London March 2015
Themes Plugins and Accessibility - WordCamp London March 2015Themes Plugins and Accessibility - WordCamp London March 2015
Themes Plugins and Accessibility - WordCamp London March 2015Graham Armfield
 
Themes, Plugins and Accessibility
Themes, Plugins and AccessibilityThemes, Plugins and Accessibility
Themes, Plugins and AccessibilityGraham Armfield
 
So How Do I Know if My Website is Accessible?
So How Do I Know if My Website is Accessible?So How Do I Know if My Website is Accessible?
So How Do I Know if My Website is Accessible?Graham Armfield
 
Handling User Generated Content in WordPress
Handling User Generated Content in WordPressHandling User Generated Content in WordPress
Handling User Generated Content in WordPressGraham Armfield
 
So, How Do I Know if my WordPress Website is Accessible?
So, How Do I Know if my WordPress Website is Accessible?So, How Do I Know if my WordPress Website is Accessible?
So, How Do I Know if my WordPress Website is Accessible?Graham Armfield
 
Web Accessibility: What it is, Why it's important
Web Accessibility: What it is, Why it's importantWeb Accessibility: What it is, Why it's important
Web Accessibility: What it is, Why it's importantGraham Armfield
 
Assistive Technology Demo Londonweb
Assistive Technology Demo LondonwebAssistive Technology Demo Londonweb
Assistive Technology Demo LondonwebGraham Armfield
 
Towards an Alternate WordPress Theme Structure
Towards an Alternate WordPress Theme StructureTowards an Alternate WordPress Theme Structure
Towards an Alternate WordPress Theme StructureGraham Armfield
 

Plus de Graham Armfield (20)

Useful Accessibility Tools Version 3 - Jul 2021
Useful Accessibility Tools Version 3 - Jul 2021Useful Accessibility Tools Version 3 - Jul 2021
Useful Accessibility Tools Version 3 - Jul 2021
 
So how do i know if my wordpress website is accessible - WordPress Accessibil...
So how do i know if my wordpress website is accessible - WordPress Accessibil...So how do i know if my wordpress website is accessible - WordPress Accessibil...
So how do i know if my wordpress website is accessible - WordPress Accessibil...
 
Useful Accessibility Tools - WordCamp Brighton
Useful Accessibility Tools - WordCamp BrightonUseful Accessibility Tools - WordCamp Brighton
Useful Accessibility Tools - WordCamp Brighton
 
Accessibility Hacks Version 2
Accessibility Hacks Version 2Accessibility Hacks Version 2
Accessibility Hacks Version 2
 
Accessibility Hacks version 2
Accessibility Hacks version 2Accessibility Hacks version 2
Accessibility Hacks version 2
 
Useful Accessibility Tools - WP Pompey April 2019
Useful Accessibility Tools - WP Pompey April 2019Useful Accessibility Tools - WP Pompey April 2019
Useful Accessibility Tools - WP Pompey April 2019
 
How to Build an Accessible WordPress Theme
How to Build an Accessible WordPress ThemeHow to Build an Accessible WordPress Theme
How to Build an Accessible WordPress Theme
 
Accessibility Hacks Wordcamp Manchester October 2018
Accessibility Hacks Wordcamp Manchester October 2018Accessibility Hacks Wordcamp Manchester October 2018
Accessibility Hacks Wordcamp Manchester October 2018
 
Useful Accessibility Tools
Useful Accessibility ToolsUseful Accessibility Tools
Useful Accessibility Tools
 
Assistive technology Demo WordCamp Bristol
Assistive technology Demo WordCamp BristolAssistive technology Demo WordCamp Bristol
Assistive technology Demo WordCamp Bristol
 
Designing for Accessibility - WordCamp London 2017
Designing for Accessibility - WordCamp London 2017Designing for Accessibility - WordCamp London 2017
Designing for Accessibility - WordCamp London 2017
 
Designing for Accessibility - Front End North - September 2016
Designing for Accessibility - Front End North - September 2016Designing for Accessibility - Front End North - September 2016
Designing for Accessibility - Front End North - September 2016
 
Themes Plugins and Accessibility - WordCamp London March 2015
Themes Plugins and Accessibility - WordCamp London March 2015Themes Plugins and Accessibility - WordCamp London March 2015
Themes Plugins and Accessibility - WordCamp London March 2015
 
Themes, Plugins and Accessibility
Themes, Plugins and AccessibilityThemes, Plugins and Accessibility
Themes, Plugins and Accessibility
 
So How Do I Know if My Website is Accessible?
So How Do I Know if My Website is Accessible?So How Do I Know if My Website is Accessible?
So How Do I Know if My Website is Accessible?
 
Handling User Generated Content in WordPress
Handling User Generated Content in WordPressHandling User Generated Content in WordPress
Handling User Generated Content in WordPress
 
So, How Do I Know if my WordPress Website is Accessible?
So, How Do I Know if my WordPress Website is Accessible?So, How Do I Know if my WordPress Website is Accessible?
So, How Do I Know if my WordPress Website is Accessible?
 
Web Accessibility: What it is, Why it's important
Web Accessibility: What it is, Why it's importantWeb Accessibility: What it is, Why it's important
Web Accessibility: What it is, Why it's important
 
Assistive Technology Demo Londonweb
Assistive Technology Demo LondonwebAssistive Technology Demo Londonweb
Assistive Technology Demo Londonweb
 
Towards an Alternate WordPress Theme Structure
Towards an Alternate WordPress Theme StructureTowards an Alternate WordPress Theme Structure
Towards an Alternate WordPress Theme Structure
 

Dernier

"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"growthgrids
 
Call girls Service in Ajman 0505086370 Ajman call girls
Call girls Service in Ajman 0505086370 Ajman call girlsCall girls Service in Ajman 0505086370 Ajman call girls
Call girls Service in Ajman 0505086370 Ajman call girlsMonica Sydney
 
Best SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency DallasBest SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency DallasDigicorns Technologies
 
一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理F
 
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...kumargunjan9515
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtrahman018755
 
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime NagercoilNagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoilmeghakumariji156
 
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdfMatthew Sinclair
 
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu DhabiAbu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu DhabiMonica Sydney
 
Mira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call GirlsMira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call GirlsPriya Reddy
 
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样ayvbos
 
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdfMatthew Sinclair
 
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrStory Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrHenryBriggs2
 
Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.krishnachandrapal52
 
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdfMatthew Sinclair
 
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girlsRussian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girlsMonica Sydney
 
一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理F
 
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsIndian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsMonica Sydney
 
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查ydyuyu
 

Dernier (20)

"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
 
Call girls Service in Ajman 0505086370 Ajman call girls
Call girls Service in Ajman 0505086370 Ajman call girlsCall girls Service in Ajman 0505086370 Ajman call girls
Call girls Service in Ajman 0505086370 Ajman call girls
 
Best SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency DallasBest SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency Dallas
 
一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理
 
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirt
 
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime NagercoilNagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
 
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
 
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu DhabiAbu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
 
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
 
Mira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call GirlsMira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
 
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
 
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
 
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrStory Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
 
Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.
 
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
 
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girlsRussian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
 
一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理
 
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsIndian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
 
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
 

Obscure Wordpress Functions That Are Actually Quite Useful

  • 1. Coolfields Consulting www.coolfields.co.uk @coolfields Obscure WordPress Functions that are actually quite useful… Graham Armfield Web Accessibility Consultant WordPress Developer graham.armfield@coolfields.co.uk @coolfields
  • 2. Obscure? Really? Well, maybe not known to everyone… 2
  • 3. Formatting text wpautop($str); • Adds in line breaks and paragraphs • Useful for printing textarea custom fields 3
  • 4. Formatting text But… sometimes wpautop() goes too far • Adds in empty paragraphs • <div> elements in paragraphs • Often happens when using shortcodes • Can be down to the order that things get done 4
  • 5. Removing empty paragraphs remove_filter( 'the_content', 'wpautop' ); add_filter( 'the_content', 'wpautop' , 99); function remove_empty_p($content){ $content = force_balance_tags($content); return preg_replace('#<p>s*+(<brs*/*>)?s*</p>#i', '', $content); } add_filter('the_content', 'remove_empty_p', 20, 1); 5
  • 6. More on shortcodes Allow shortcodes to be interpreted in widgets: add_filter('widget_text', 'do_shortcode'); Remove all shortcodes from a string: strip_shortcodes( $content ); 6
  • 7. Excerpts The default length is 55 words. You can change this… function custom_excerpt_length( $length ) { return 30; } add_filter( 'excerpt_length', custom_excerpt_length', 999 ); 7
  • 8. Localizing dates Post/page published dates get localized automatically by WP when site's language changes. But, what if you have to set date formats in PHP? 8
  • 9. Localizing dates Eg: Custom fields may have date in database format: 2016-02-25 This is useful for sorting, and selecting using wp_query(); You may need to output: 25 Chwefror 2016 9
  • 10. Localizing dates Setting the locale in PHP can be a pain. So use the WordPress capability instead – date_i18n($pattern, $timestamp); 10
  • 11. Localizing dates function db_date_format($str_date, $pattern = ''){ // incoming format = yyyy-mm-dd if (empty($pattern)) { $pattern = get_option( 'date_format' ); } $time_stamp = mktime(0,0,0,substr($str_date,5,2), substr ($str_date,8,2),substr($str_date,0,4)); return date_i18n( $pattern, $time_stamp ); } 11
  • 12. Pagination On blog index pages, using previous_posts_link() and next_posts_link() is OK… But it doesn't give site visitors an indication of how many blog posts there are altogether. Pagination may give better usability… 12
  • 13. Pagination global $wp_query; if ($wp_query->max_num_pages > 1) { $big = 999999999; // need an unlikely integer echo paginate_links( array( 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link($big) ) ), 'format' => '?paged=%#%', 'current' => max( 1, get_query_var('paged') ), 'total' => $wp_query->max_num_pages, 'end_size' => 3, 'type' => 'list', 'prev_text' => '&laquo; Newer<span class="srdr"> posts</span>', 'next_text' => 'Older<span class="srdr"> posts</span> &raquo;', 'before_page_number' => '<span class="srdr">Page </span>', 'after_page_number' => '' ) ); } Can use this with custom queries too. 13