SlideShare a Scribd company logo
1 of 47
Download to read offline
Montreal WordCamp 2015
@MichaelBontyes
[i-am-a-shortcode]
A shortcode is a WordPress-specific code
that lets you do nifty things with very little effort.
Shortcodes can embed files or create objects that
would normally require lots of complicated,
ugly code in just one line.
Shortcode = shortcut.
https://en.support.wordpress.com/shortcodes/
// Use shortcode in a PHP file (outside the post editor).
echo do_shortcode( '[hello]' );
https://codex.wordpress.org/Function_Reference/do_shortcode
<?php
function hello() {
return "Hello WordCamp Mtl !";
}
add_shortcode( 'hello' , 'hello' );
​?>
Site / Page
Editor
Functions
Hello WordCamp Mtl !
[hello]
Wordpress.com … & WordCamp.org!
[gallery type=”rectangular”]
https://en.support.wordpress.com/shortcodes/
Jetpack.me
http://jetpack.me/support/subscriptions/
[jetpack_subscription_form]
Développeurs de thèmes
Développeurs de plugins
[geo_mashup_map]
https://github.com/cyberhobo/wordpress-geo-mashup/wiki/Getting-Started
Développeurs de plugins
[timeline-express]
https://github.com/EvanHerman/Timeline-Express
+
+
un peu de
Simple
add_shortcode()
Paramétrable
shortcode_atts()
Flexible
do_shortcode()
Complexe
ob_start()
add_shortcode()
Functions.php / includes / plugin Shortcode
1 <?php
Résultat
add_shortcode()
Functions.php / includes / plugin Shortcode
1
2
3
4
5
6
7
8
<?php
// Create the function for the shortcode
function message_maker() {
}
​?>
Résultat
add_shortcode()
Functions.php / includes / plugin Shortcode
1
2
3
4
5
6
7
8
9
10
<?php
// Create the function for the shortcode
function message_maker() {
return 'Hello WordCamp Mtl !';
}
​?>
Résultat
add_shortcode()
Functions.php / includes / plugin Shortcode
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
// Create the function for the shortcode
function message_maker() {
return 'Hello WordCamp Mtl !';
}
// Register the Shortcode using the API
add_shortcode('message' , 'message_maker' );
​?>
Résultat
add_shortcode()
Functions.php / includes / plugin Shortcode
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
// Create the function for the shortcode
function message_maker() {
return 'Hello WordCamp Mtl !';
}
// Register the Shortcode using the API
add_shortcode('message' , 'message_maker' );
​?>
[message]
Résultat
add_shortcode()
Functions.php / includes / plugin Shortcode
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
// Create the function for the shortcode
function message_maker() {
return 'Hello WordCamp Mtl !';
}
// Register the Shortcode using the API
add_shortcode('message' , 'message_maker' );
​?>
[message]
Résultat
Hello WordCamp Mtl !
Functions.php / includes / plugin Shortcode
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
// Create the function for the shortcode
function current_year() {
return date('Y');
}
// Register the Shortcode using the API
add_shortcode('year' , 'current_year' );
​?>
Résultat
Functions.php / includes / plugin Shortcode
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
// Create the function for the shortcode
function current_year() {
return date('Y');
}
// Register the Shortcode using the API
add_shortcode('year' , 'current_year' );
​?>
[year]
Résultat
Functions.php / includes / plugin Shortcode
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
// Create the function for the shortcode
function current_year() {
return date('Y');
}
// Register the Shortcode using the API
add_shortcode('year' , 'current_year' );
​?>
[year]
Résultat
2015
Simple
add_shortcode()
Paramétrable
shortcode_atts()
Flexible
do_shortcode()
Complexe
ob_start()
shortcode_atts()
Functions.php / includes / plugin Shortcode
1
2
3
4
5
6
7
8
9
<?php
// Create the shortcode function
function lorem_ipsum() {
}
// Register the Shortcode using the API
add_shortcode( 'lorem' , 'lorem_ipsum' );
?>
Résultat
shortcode_atts()
Functions.php / includes / plugin Shortcode
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
// Create the shortcode function
function lorem_ipsum( $atts ) {
// Handling the Attributes
$a = shortcode_atts( array(
'sentences' => 1
), $atts );
}
// Register the Shortcode using the API
add_shortcode( 'lorem' , 'lorem_ipsum' );
?>
Résultat
shortcode_atts()
Functions.php / includes / plugin Shortcode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
// Create the shortcode function
function lorem_ipsum( $atts ) {
// Handling the Attributes
$a = shortcode_atts( array(
'sentences' => 1
), $atts );
// Get the Lorem Ipsum
$lorem_ipsum = get_lorem_ipsum( $a['sentences'] );
return $lorem_ipsum;
}
// Register the Shortcode using the API
add_shortcode( 'lorem' , 'lorem_ipsum' );
?>
Résultat
shortcode_atts()
Functions.php / includes / plugin Shortcode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
// Create the shortcode function
function lorem_ipsum( $atts ) {
// Handling the Attributes
$a = shortcode_atts( array(
'sentences' => 1
), $atts );
// Get the Lorem Ipsum
$lorem_ipsum = get_lorem_ipsum( $a['sentences'] );
return $lorem_ipsum;
}
// Register the Shortcode using the API
add_shortcode( 'lorem' , 'lorem_ipsum' );
?>
[lorem sentences=“2”]
Résultat
shortcode_atts()
Functions.php / includes / plugin Shortcode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
// Create the shortcode function
function lorem_ipsum( $atts ) {
// Handling the Attributes
$a = shortcode_atts( array(
'sentences' => 1
), $atts );
// Get the Lorem Ipsum
$lorem_ipsum = get_lorem_ipsum( $a['sentences'] );
return $lorem_ipsum;
}
// Register the Shortcode using the API
add_shortcode( 'lorem' , 'lorem_ipsum' );
?>
[lorem sentences=“2”]
Résultat
Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
Aliter enim explicari, quod
quaeritur, non potest.
shortcode_atts()
Functions.php / includes / plugin Shortcode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
// Create the shortcode function
function get_thumbnail( $atts ) {
// Handling the Attributes
$a = shortcode_atts( array(
'size' => 'thumbnail',
'class' => 'circle'
), $atts );
// Get the Thumbnail
echo get_the_post_thumbnail(
get_option('page_on_front'), $a['size'],
array( 'class' => $a['class'] ) );
}
// Register the Shortcode using the API
add_shortcode( 'thumbnail' , 'get_thumbnail' );
?>
Résultat
shortcode_atts()
Functions.php / includes / plugin Shortcode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
// Create the shortcode function
function get_thumbnail( $atts ) {
// Handling the Attributes
$a = shortcode_atts( array(
'size' => 'thumbnail',
'class' => 'circle'
), $atts );
// Get the Thumbnail
echo get_the_post_thumbnail(
get_option('page_on_front'), $a['size'],
array( 'class' => $a['class'] ) );
}
// Register the Shortcode using the API
add_shortcode( 'thumbnail' , 'get_thumbnail' );
?>
[thumbnail size=”medium”
class=“circle”]
Résultat
shortcode_atts()
Functions.php / includes / plugin Shortcode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
// Create the shortcode function
function get_thumbnail( $atts ) {
// Handling the Attributes
$a = shortcode_atts( array(
'size' => 'thumbnail',
'class' => 'circle'
), $atts );
// Get the Thumbnail
return get_the_post_thumbnail(
get_option('page_on_front'), $a['size'],
array( 'class' => $a['class'] ) );
}
// Register the Shortcode using the API
add_shortcode( 'thumbnail' , 'get_thumbnail' );
?>
[thumbnail size=”medium”
class=“circle”]
Résultat
Simple
add_shortcode()
Paramétrable
shortcode_atts()
Flexible
do_shortcode()
Complexe
ob_start()
$content
Functions.php / includes / plugin Shortcode
1
2
3
4
5
6
7
8
9
10
11
<?php
// Create the function for the shortcode
function message_maker( $atts ) {
}
// Register the Shortcode using the API
add_shortcode('message' , 'message_maker' );
​?>
Résultat
$content
Functions.php / includes / plugin Shortcode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
// Create the function for the shortcode
function message_maker( $atts, $content = null ) {
// Upper the $content
return strtoupper($content);
}
// Register the Shortcode using the API
add_shortcode('message' , 'message_maker' );
​?>
Résultat
$content
Functions.php / includes / plugin Shortcode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
// Create the function for the shortcode
function message_maker( $atts, $content = null ) {
// Upper the $content
return strtoupper($content);
}
// Register the Shortcode using the API
add_shortcode('message' , 'message_maker' );
​?>
[message]
tout ce paragraphe
devrait être en
lettres capitales
[/message]
Résultat
$content
Functions.php / includes / plugin Shortcode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
// Create the function for the shortcode
function message_maker( $atts, $content = null ) {
// Upper the $content
return strtoupper($content);
}
// Register the Shortcode using the API
add_shortcode('message' , 'message_maker' );
​?>
[message]
tout ce paragraphe
devrait être en
lettres capitales
[/message]
Résultat
TOUT CE PARAGRAPHE
DEVRAIT ÊTRE EN
LETTRES CAPITALES
do_shortcode()
Functions.php / includes / plugin Shortcode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
// Create the function for the shortcode
function message_maker( $atts, $content = null ) {
// Upper the $content
return strtoupper(do_shortcode($content));
}
// Register the Shortcode using the API
add_shortcode('message' , 'message_maker' );
​?>
Résultat
do_shortcode()
Functions.php / includes / plugin Shortcode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
// Create the function for the shortcode
function message_maker( $atts, $content = null ) {
// Upper the $content
return strtoupper(do_shortcode($content));
}
// Register the Shortcode using the API
add_shortcode('message' , 'message_maker' );
​?>
[message]
Hello WordCamp Montreal
[year] !
[/message]
Résultat
do_shortcode()
Functions.php / includes / plugin Shortcode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
// Create the function for the shortcode
function message_maker( $atts, $content = null ) {
// Upper the $content
return strtoupper(do_shortcode($content));
}
// Register the Shortcode using the API
add_shortcode('message' , 'message_maker' );
​?>
[message]
Hello WordCamp Montreal
[year] !
[/message]
Résultat
HELLO WORDCAMP MONTREAL
2015 !
Simple
add_shortcode()
Paramétrable
shortcode_atts()
Flexible
do_shortcode()
Complexe
ob_start()
ob_start()
Functions.php / includes / plugin Shortcode
1
2
3
4
5
6
7
8
<?php
// Create the shortcode function
function message_maker() {
}
// Register the Shortcode using the API
add_shortcode('message' , 'message_maker' );
?>
Résultat
ob_start()
Functions.php / includes / plugin Shortcode
1
2
3
4
5
6
7
8
9
10
11
<?php
// Create the shortcode function
function message_maker() {
// Démarrage du buffer de sortie
ob_start();
}
// Register the Shortcode using the API
add_shortcode('message' , 'message_maker' );
?>
Résultat
ob_start()
Functions.php / includes / plugin Shortcode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
// Create the shortcode function
function message_maker() {
// Démarrage du buffer de sortie
ob_start();
?>
<ul>
<li>Post title 1</li>
<li>Post title 2</li>
</ul>
<?php
}
// Register the Shortcode using the API
add_shortcode('message' , 'message_maker' );
?>
Résultat
ob_start()
Functions.php / includes / plugin Shortcode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
// Create the shortcode function
function message_maker() {
// Démarrage du buffer de sortie
ob_start();
?>
<ul>
<li>Post title 1</li>
<li>Post title 2</li>
</ul>
<?php
// Lecture du buffer et effacement
return ob_get_clean();
}
Résultat
ob_start()
Functions.php / includes / plugin Shortcode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
// Create the shortcode function
function message_maker() {
// Démarrage du buffer de sortie
ob_start();
?>
<ul>
<li>Post title 1</li>
<li>Post title 2</li>
</ul>
<?php
// Lecture du buffer et effacement
return ob_get_clean();
}
[message]
Résultat
ob_start()
Functions.php / includes / plugin Shortcode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
// Create the shortcode function
function message_maker() {
// Démarrage du buffer de sortie
ob_start();
?>
<ul>
<li>Post title 1</li>
<li>Post title 2</li>
</ul>
<?php
// Lecture du buffer et effacement
return ob_get_clean();
}
[message]
Résultat
• Post Title 1
• Post Title 2
Functions.php / includes / plugin Shortcode
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
function show_posts( $atts, $content = null ) {
// Handling the Attributes
$a = shortcode_atts( array(
'type' => 'projects'
), $atts );
// Get the posts filtered by Post Type
$query = new WP_Query( array( 'post_type' => $a['type'] ) );
ob_start();
echo '<h1>'.do_shortcode($content).'</h1>';
echo '<ul>‘;
// The WP Query Loop
while ( $query->have_posts() ) {
$query->the_post(); ?>
<!-- Build the HTML -->
<li><?php the_title(); ?></li>
</ul>
<?php }
echo '</ul>‘;
// Restore the Global $post variable - Avoid WP Query inception conflict
wp_reset_postdata();
return ob_get_clean();
}
add_shortcode('posts' , 'show_posts' );
[posts type=“projects”]
Mes derniers projets :
[/posts]
Résultat
Mes derniers projets :
• Project Title 1
• Project Title 2
• Project Title 3
http://gndev.info/shortcodes-ultimate/
Shortcodes Ultimate for WordPress Including a custom
shortcode maker
API / Addon
https://github.com/gndev/shortcodes-ultimate
https://codex.wordpress.org/Shortcode_API
Wordpress Codex – Shortcode API
Montreal WordCamp 2015 | @MichaelBontyes
https://github.com/michaelbontyes/Presentation-Create-Your-Own-Shortcode
Presentation “How to create your own shortcode”

More Related Content

What's hot

Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram VaswaniCreating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswanivvaswani
 
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years laterSymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years laterHaehnchen
 
Flutter State Management Using GetX.pdf
Flutter State Management Using GetX.pdfFlutter State Management Using GetX.pdf
Flutter State Management Using GetX.pdfKaty Slemon
 
Caldera Learn - LoopConf WP API + Angular FTW Workshop
Caldera Learn - LoopConf WP API + Angular FTW WorkshopCaldera Learn - LoopConf WP API + Angular FTW Workshop
Caldera Learn - LoopConf WP API + Angular FTW WorkshopCalderaLearn
 
Keeping the frontend under control with Symfony and Webpack
Keeping the frontend under control with Symfony and WebpackKeeping the frontend under control with Symfony and Webpack
Keeping the frontend under control with Symfony and WebpackIgnacio Martín
 
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...Caldera Labs
 
Build a video chat application with twilio, rails, and javascript (part 1)
Build a video chat application with twilio, rails, and javascript (part 1)Build a video chat application with twilio, rails, and javascript (part 1)
Build a video chat application with twilio, rails, and javascript (part 1)Katy Slemon
 
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and moreSymfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and moreRyan Weaver
 
Rails antipatterns
Rails antipatternsRails antipatterns
Rails antipatternsChul Ju Hong
 
Rails antipattern-public
Rails antipattern-publicRails antipattern-public
Rails antipattern-publicChul Ju Hong
 
Silex: From nothing to an API
Silex: From nothing to an APISilex: From nothing to an API
Silex: From nothing to an APIchrisdkemper
 
Using Renderless Components in Vue.js during your software development.
Using Renderless Components in Vue.js during your software development.Using Renderless Components in Vue.js during your software development.
Using Renderless Components in Vue.js during your software development.tothepointIT
 
Introduction to AngularJS For WordPress Developers
Introduction to AngularJS For WordPress DevelopersIntroduction to AngularJS For WordPress Developers
Introduction to AngularJS For WordPress DevelopersCaldera Labs
 

What's hot (20)

Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram VaswaniCreating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
 
Boost your angular app with web workers
Boost your angular app with web workersBoost your angular app with web workers
Boost your angular app with web workers
 
Symfony2 and AngularJS
Symfony2 and AngularJSSymfony2 and AngularJS
Symfony2 and AngularJS
 
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years laterSymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
 
Flutter State Management Using GetX.pdf
Flutter State Management Using GetX.pdfFlutter State Management Using GetX.pdf
Flutter State Management Using GetX.pdf
 
Caldera Learn - LoopConf WP API + Angular FTW Workshop
Caldera Learn - LoopConf WP API + Angular FTW WorkshopCaldera Learn - LoopConf WP API + Angular FTW Workshop
Caldera Learn - LoopConf WP API + Angular FTW Workshop
 
Keeping the frontend under control with Symfony and Webpack
Keeping the frontend under control with Symfony and WebpackKeeping the frontend under control with Symfony and Webpack
Keeping the frontend under control with Symfony and Webpack
 
Complex Sites with Silex
Complex Sites with SilexComplex Sites with Silex
Complex Sites with Silex
 
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...
 
REST API for your WP7 App
REST API for your WP7 AppREST API for your WP7 App
REST API for your WP7 App
 
Build a video chat application with twilio, rails, and javascript (part 1)
Build a video chat application with twilio, rails, and javascript (part 1)Build a video chat application with twilio, rails, and javascript (part 1)
Build a video chat application with twilio, rails, and javascript (part 1)
 
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and moreSymfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
 
Laravel 101
Laravel 101Laravel 101
Laravel 101
 
Symfony 2
Symfony 2Symfony 2
Symfony 2
 
Rails antipatterns
Rails antipatternsRails antipatterns
Rails antipatterns
 
Rails antipattern-public
Rails antipattern-publicRails antipattern-public
Rails antipattern-public
 
Silex: From nothing to an API
Silex: From nothing to an APISilex: From nothing to an API
Silex: From nothing to an API
 
Elefrant [ng-Poznan]
Elefrant [ng-Poznan]Elefrant [ng-Poznan]
Elefrant [ng-Poznan]
 
Using Renderless Components in Vue.js during your software development.
Using Renderless Components in Vue.js during your software development.Using Renderless Components in Vue.js during your software development.
Using Renderless Components in Vue.js during your software development.
 
Introduction to AngularJS For WordPress Developers
Introduction to AngularJS For WordPress DevelopersIntroduction to AngularJS For WordPress Developers
Introduction to AngularJS For WordPress Developers
 

Similar to WCMTL 15 - Create your own shortcode (Fr)

HTTP Middlewares in PHP by Eugene Dounar
HTTP Middlewares in PHP by Eugene DounarHTTP Middlewares in PHP by Eugene Dounar
HTTP Middlewares in PHP by Eugene DounarMinsk PHP User Group
 
[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress DevelopmentAdam Tomat
 
Building Cloud Castles
Building Cloud CastlesBuilding Cloud Castles
Building Cloud CastlesBen Scofield
 
WordCamp Montreal 2016 WP-API + React with server rendering
WordCamp Montreal 2016  WP-API + React with server renderingWordCamp Montreal 2016  WP-API + React with server rendering
WordCamp Montreal 2016 WP-API + React with server renderingZiad Saab
 
Speed up your developments with Symfony2
Speed up your developments with Symfony2Speed up your developments with Symfony2
Speed up your developments with Symfony2Hugo Hamon
 
Shortcodes In-Depth
Shortcodes In-DepthShortcodes In-Depth
Shortcodes In-DepthMicah Wood
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkBo-Yi Wu
 
Intro To Mvc Development In Php
Intro To Mvc Development In PhpIntro To Mvc Development In Php
Intro To Mvc Development In Phpfunkatron
 
Ch ch-changes cake php2
Ch ch-changes cake php2Ch ch-changes cake php2
Ch ch-changes cake php2markstory
 
Benefit of CodeIgniter php framework
Benefit of CodeIgniter php frameworkBenefit of CodeIgniter php framework
Benefit of CodeIgniter php frameworkBo-Yi Wu
 
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
 
Ruby on Rails vs ASP.NET MVC
Ruby on Rails vs ASP.NET MVCRuby on Rails vs ASP.NET MVC
Ruby on Rails vs ASP.NET MVCSimone Chiaretta
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php PresentationAlan Pinstein
 

Similar to WCMTL 15 - Create your own shortcode (Fr) (20)

Extend sdk
Extend sdkExtend sdk
Extend sdk
 
Introduction to angular js
Introduction to angular jsIntroduction to angular js
Introduction to angular js
 
Extend sdk
Extend sdkExtend sdk
Extend sdk
 
HTTP Middlewares in PHP by Eugene Dounar
HTTP Middlewares in PHP by Eugene DounarHTTP Middlewares in PHP by Eugene Dounar
HTTP Middlewares in PHP by Eugene Dounar
 
[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development
 
Building Cloud Castles
Building Cloud CastlesBuilding Cloud Castles
Building Cloud Castles
 
WordCamp Montreal 2016 WP-API + React with server rendering
WordCamp Montreal 2016  WP-API + React with server renderingWordCamp Montreal 2016  WP-API + React with server rendering
WordCamp Montreal 2016 WP-API + React with server rendering
 
Introduction to Zend Framework
Introduction to Zend FrameworkIntroduction to Zend Framework
Introduction to Zend Framework
 
Speed up your developments with Symfony2
Speed up your developments with Symfony2Speed up your developments with Symfony2
Speed up your developments with Symfony2
 
Shortcodes In-Depth
Shortcodes In-DepthShortcodes In-Depth
Shortcodes In-Depth
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC Framework
 
Intro To Mvc Development In Php
Intro To Mvc Development In PhpIntro To Mvc Development In Php
Intro To Mvc Development In Php
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
Ch ch-changes cake php2
Ch ch-changes cake php2Ch ch-changes cake php2
Ch ch-changes cake php2
 
Codegnitorppt
CodegnitorpptCodegnitorppt
Codegnitorppt
 
Benefit of CodeIgniter php framework
Benefit of CodeIgniter php frameworkBenefit of CodeIgniter php framework
Benefit of CodeIgniter php framework
 
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
 
Ruby on Rails vs ASP.NET MVC
Ruby on Rails vs ASP.NET MVCRuby on Rails vs ASP.NET MVC
Ruby on Rails vs ASP.NET MVC
 
angular fundamentals.pdf
angular fundamentals.pdfangular fundamentals.pdf
angular fundamentals.pdf
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php Presentation
 

Recently uploaded

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 

Recently uploaded (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

WCMTL 15 - Create your own shortcode (Fr)

  • 2. [i-am-a-shortcode] A shortcode is a WordPress-specific code that lets you do nifty things with very little effort. Shortcodes can embed files or create objects that would normally require lots of complicated, ugly code in just one line. Shortcode = shortcut. https://en.support.wordpress.com/shortcodes/
  • 3. // Use shortcode in a PHP file (outside the post editor). echo do_shortcode( '[hello]' ); https://codex.wordpress.org/Function_Reference/do_shortcode
  • 4. <?php function hello() { return "Hello WordCamp Mtl !"; } add_shortcode( 'hello' , 'hello' ); ​?> Site / Page Editor Functions Hello WordCamp Mtl ! [hello]
  • 5. Wordpress.com … & WordCamp.org! [gallery type=”rectangular”] https://en.support.wordpress.com/shortcodes/
  • 10.
  • 13. add_shortcode() Functions.php / includes / plugin Shortcode 1 <?php Résultat
  • 14. add_shortcode() Functions.php / includes / plugin Shortcode 1 2 3 4 5 6 7 8 <?php // Create the function for the shortcode function message_maker() { } ​?> Résultat
  • 15. add_shortcode() Functions.php / includes / plugin Shortcode 1 2 3 4 5 6 7 8 9 10 <?php // Create the function for the shortcode function message_maker() { return 'Hello WordCamp Mtl !'; } ​?> Résultat
  • 16. add_shortcode() Functions.php / includes / plugin Shortcode 1 2 3 4 5 6 7 8 9 10 11 12 13 <?php // Create the function for the shortcode function message_maker() { return 'Hello WordCamp Mtl !'; } // Register the Shortcode using the API add_shortcode('message' , 'message_maker' ); ​?> Résultat
  • 17. add_shortcode() Functions.php / includes / plugin Shortcode 1 2 3 4 5 6 7 8 9 10 11 12 13 <?php // Create the function for the shortcode function message_maker() { return 'Hello WordCamp Mtl !'; } // Register the Shortcode using the API add_shortcode('message' , 'message_maker' ); ​?> [message] Résultat
  • 18. add_shortcode() Functions.php / includes / plugin Shortcode 1 2 3 4 5 6 7 8 9 10 11 12 13 <?php // Create the function for the shortcode function message_maker() { return 'Hello WordCamp Mtl !'; } // Register the Shortcode using the API add_shortcode('message' , 'message_maker' ); ​?> [message] Résultat Hello WordCamp Mtl !
  • 19. Functions.php / includes / plugin Shortcode 1 2 3 4 5 6 7 8 9 10 11 12 13 <?php // Create the function for the shortcode function current_year() { return date('Y'); } // Register the Shortcode using the API add_shortcode('year' , 'current_year' ); ​?> Résultat
  • 20. Functions.php / includes / plugin Shortcode 1 2 3 4 5 6 7 8 9 10 11 12 13 <?php // Create the function for the shortcode function current_year() { return date('Y'); } // Register the Shortcode using the API add_shortcode('year' , 'current_year' ); ​?> [year] Résultat
  • 21. Functions.php / includes / plugin Shortcode 1 2 3 4 5 6 7 8 9 10 11 12 13 <?php // Create the function for the shortcode function current_year() { return date('Y'); } // Register the Shortcode using the API add_shortcode('year' , 'current_year' ); ​?> [year] Résultat 2015
  • 23. shortcode_atts() Functions.php / includes / plugin Shortcode 1 2 3 4 5 6 7 8 9 <?php // Create the shortcode function function lorem_ipsum() { } // Register the Shortcode using the API add_shortcode( 'lorem' , 'lorem_ipsum' ); ?> Résultat
  • 24. shortcode_atts() Functions.php / includes / plugin Shortcode 1 2 3 4 5 6 7 8 9 10 11 12 13 <?php // Create the shortcode function function lorem_ipsum( $atts ) { // Handling the Attributes $a = shortcode_atts( array( 'sentences' => 1 ), $atts ); } // Register the Shortcode using the API add_shortcode( 'lorem' , 'lorem_ipsum' ); ?> Résultat
  • 25. shortcode_atts() Functions.php / includes / plugin Shortcode 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 <?php // Create the shortcode function function lorem_ipsum( $atts ) { // Handling the Attributes $a = shortcode_atts( array( 'sentences' => 1 ), $atts ); // Get the Lorem Ipsum $lorem_ipsum = get_lorem_ipsum( $a['sentences'] ); return $lorem_ipsum; } // Register the Shortcode using the API add_shortcode( 'lorem' , 'lorem_ipsum' ); ?> Résultat
  • 26. shortcode_atts() Functions.php / includes / plugin Shortcode 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 <?php // Create the shortcode function function lorem_ipsum( $atts ) { // Handling the Attributes $a = shortcode_atts( array( 'sentences' => 1 ), $atts ); // Get the Lorem Ipsum $lorem_ipsum = get_lorem_ipsum( $a['sentences'] ); return $lorem_ipsum; } // Register the Shortcode using the API add_shortcode( 'lorem' , 'lorem_ipsum' ); ?> [lorem sentences=“2”] Résultat
  • 27. shortcode_atts() Functions.php / includes / plugin Shortcode 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 <?php // Create the shortcode function function lorem_ipsum( $atts ) { // Handling the Attributes $a = shortcode_atts( array( 'sentences' => 1 ), $atts ); // Get the Lorem Ipsum $lorem_ipsum = get_lorem_ipsum( $a['sentences'] ); return $lorem_ipsum; } // Register the Shortcode using the API add_shortcode( 'lorem' , 'lorem_ipsum' ); ?> [lorem sentences=“2”] Résultat Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliter enim explicari, quod quaeritur, non potest.
  • 28. shortcode_atts() Functions.php / includes / plugin Shortcode 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 <?php // Create the shortcode function function get_thumbnail( $atts ) { // Handling the Attributes $a = shortcode_atts( array( 'size' => 'thumbnail', 'class' => 'circle' ), $atts ); // Get the Thumbnail echo get_the_post_thumbnail( get_option('page_on_front'), $a['size'], array( 'class' => $a['class'] ) ); } // Register the Shortcode using the API add_shortcode( 'thumbnail' , 'get_thumbnail' ); ?> Résultat
  • 29. shortcode_atts() Functions.php / includes / plugin Shortcode 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 <?php // Create the shortcode function function get_thumbnail( $atts ) { // Handling the Attributes $a = shortcode_atts( array( 'size' => 'thumbnail', 'class' => 'circle' ), $atts ); // Get the Thumbnail echo get_the_post_thumbnail( get_option('page_on_front'), $a['size'], array( 'class' => $a['class'] ) ); } // Register the Shortcode using the API add_shortcode( 'thumbnail' , 'get_thumbnail' ); ?> [thumbnail size=”medium” class=“circle”] Résultat
  • 30. shortcode_atts() Functions.php / includes / plugin Shortcode 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 <?php // Create the shortcode function function get_thumbnail( $atts ) { // Handling the Attributes $a = shortcode_atts( array( 'size' => 'thumbnail', 'class' => 'circle' ), $atts ); // Get the Thumbnail return get_the_post_thumbnail( get_option('page_on_front'), $a['size'], array( 'class' => $a['class'] ) ); } // Register the Shortcode using the API add_shortcode( 'thumbnail' , 'get_thumbnail' ); ?> [thumbnail size=”medium” class=“circle”] Résultat
  • 32. $content Functions.php / includes / plugin Shortcode 1 2 3 4 5 6 7 8 9 10 11 <?php // Create the function for the shortcode function message_maker( $atts ) { } // Register the Shortcode using the API add_shortcode('message' , 'message_maker' ); ​?> Résultat
  • 33. $content Functions.php / includes / plugin Shortcode 1 2 3 4 5 6 7 8 9 10 11 12 13 14 <?php // Create the function for the shortcode function message_maker( $atts, $content = null ) { // Upper the $content return strtoupper($content); } // Register the Shortcode using the API add_shortcode('message' , 'message_maker' ); ​?> Résultat
  • 34. $content Functions.php / includes / plugin Shortcode 1 2 3 4 5 6 7 8 9 10 11 12 13 14 <?php // Create the function for the shortcode function message_maker( $atts, $content = null ) { // Upper the $content return strtoupper($content); } // Register the Shortcode using the API add_shortcode('message' , 'message_maker' ); ​?> [message] tout ce paragraphe devrait être en lettres capitales [/message] Résultat
  • 35. $content Functions.php / includes / plugin Shortcode 1 2 3 4 5 6 7 8 9 10 11 12 13 14 <?php // Create the function for the shortcode function message_maker( $atts, $content = null ) { // Upper the $content return strtoupper($content); } // Register the Shortcode using the API add_shortcode('message' , 'message_maker' ); ​?> [message] tout ce paragraphe devrait être en lettres capitales [/message] Résultat TOUT CE PARAGRAPHE DEVRAIT ÊTRE EN LETTRES CAPITALES
  • 36. do_shortcode() Functions.php / includes / plugin Shortcode 1 2 3 4 5 6 7 8 9 10 11 12 13 14 <?php // Create the function for the shortcode function message_maker( $atts, $content = null ) { // Upper the $content return strtoupper(do_shortcode($content)); } // Register the Shortcode using the API add_shortcode('message' , 'message_maker' ); ​?> Résultat
  • 37. do_shortcode() Functions.php / includes / plugin Shortcode 1 2 3 4 5 6 7 8 9 10 11 12 13 14 <?php // Create the function for the shortcode function message_maker( $atts, $content = null ) { // Upper the $content return strtoupper(do_shortcode($content)); } // Register the Shortcode using the API add_shortcode('message' , 'message_maker' ); ​?> [message] Hello WordCamp Montreal [year] ! [/message] Résultat
  • 38. do_shortcode() Functions.php / includes / plugin Shortcode 1 2 3 4 5 6 7 8 9 10 11 12 13 14 <?php // Create the function for the shortcode function message_maker( $atts, $content = null ) { // Upper the $content return strtoupper(do_shortcode($content)); } // Register the Shortcode using the API add_shortcode('message' , 'message_maker' ); ​?> [message] Hello WordCamp Montreal [year] ! [/message] Résultat HELLO WORDCAMP MONTREAL 2015 !
  • 40. ob_start() Functions.php / includes / plugin Shortcode 1 2 3 4 5 6 7 8 <?php // Create the shortcode function function message_maker() { } // Register the Shortcode using the API add_shortcode('message' , 'message_maker' ); ?> Résultat
  • 41. ob_start() Functions.php / includes / plugin Shortcode 1 2 3 4 5 6 7 8 9 10 11 <?php // Create the shortcode function function message_maker() { // Démarrage du buffer de sortie ob_start(); } // Register the Shortcode using the API add_shortcode('message' , 'message_maker' ); ?> Résultat
  • 42. ob_start() Functions.php / includes / plugin Shortcode 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 <?php // Create the shortcode function function message_maker() { // Démarrage du buffer de sortie ob_start(); ?> <ul> <li>Post title 1</li> <li>Post title 2</li> </ul> <?php } // Register the Shortcode using the API add_shortcode('message' , 'message_maker' ); ?> Résultat
  • 43. ob_start() Functions.php / includes / plugin Shortcode 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 <?php // Create the shortcode function function message_maker() { // Démarrage du buffer de sortie ob_start(); ?> <ul> <li>Post title 1</li> <li>Post title 2</li> </ul> <?php // Lecture du buffer et effacement return ob_get_clean(); } Résultat
  • 44. ob_start() Functions.php / includes / plugin Shortcode 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 <?php // Create the shortcode function function message_maker() { // Démarrage du buffer de sortie ob_start(); ?> <ul> <li>Post title 1</li> <li>Post title 2</li> </ul> <?php // Lecture du buffer et effacement return ob_get_clean(); } [message] Résultat
  • 45. ob_start() Functions.php / includes / plugin Shortcode 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 <?php // Create the shortcode function function message_maker() { // Démarrage du buffer de sortie ob_start(); ?> <ul> <li>Post title 1</li> <li>Post title 2</li> </ul> <?php // Lecture du buffer et effacement return ob_get_clean(); } [message] Résultat • Post Title 1 • Post Title 2
  • 46. Functions.php / includes / plugin Shortcode 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 function show_posts( $atts, $content = null ) { // Handling the Attributes $a = shortcode_atts( array( 'type' => 'projects' ), $atts ); // Get the posts filtered by Post Type $query = new WP_Query( array( 'post_type' => $a['type'] ) ); ob_start(); echo '<h1>'.do_shortcode($content).'</h1>'; echo '<ul>‘; // The WP Query Loop while ( $query->have_posts() ) { $query->the_post(); ?> <!-- Build the HTML --> <li><?php the_title(); ?></li> </ul> <?php } echo '</ul>‘; // Restore the Global $post variable - Avoid WP Query inception conflict wp_reset_postdata(); return ob_get_clean(); } add_shortcode('posts' , 'show_posts' ); [posts type=“projects”] Mes derniers projets : [/posts] Résultat Mes derniers projets : • Project Title 1 • Project Title 2 • Project Title 3
  • 47. http://gndev.info/shortcodes-ultimate/ Shortcodes Ultimate for WordPress Including a custom shortcode maker API / Addon https://github.com/gndev/shortcodes-ultimate https://codex.wordpress.org/Shortcode_API Wordpress Codex – Shortcode API Montreal WordCamp 2015 | @MichaelBontyes https://github.com/michaelbontyes/Presentation-Create-Your-Own-Shortcode Presentation “How to create your own shortcode”

Editor's Notes

  1. 5’ Introduction : - Remerciements – 1ere fois – team - On va parler des shortcodes en 3 parties : intro, code, q-a -> question voisins si pas voisin stopper moi! Sondage MAIS premiere question , c’est quoi un SHORTCODE???
  2. Exemple
  3. Exemple
  4. page / post / custom post type widget
  5. ******* 5’ ******* TOUT gratuit ou open source!
  6. ******* 10’ ******* Gratuit ! Pas de plugin en plus !
  7. Type et caracteristiques des SHORTCODES
  8. Function principale en VERT Dans FUNCTIONS, INC ou PLUGIN PRECEDURALE OU EN ORIENTE OBJET
  9. ON ENREGISTRE LE SHORTCODE
  10. Shortcode dans la page de la homepage par exemple
  11. Exemple du copyright ou signature en bas de page
  12. ******* 15’ *******
  13. Example du lorem ipsum pour l’integrateur et son CSS
  14. Get_lorem autre function utilisant l’API lorem ipsum
  15. Et si je dois prendre en compte tout un paragraphes ou plusieurs??
  16. Mise en capitales
  17. Comme des balises HTML – CLOSING TAG
  18. ET si on compliquait un peu??? Exemple de texte en capital avec la date ou une signature a la fin Ou une image de homepage
  19. ******* 20’ *******
  20. example de la LOOP Attention au wp_reset_query
  21. Buffer / tampon / temporisateur de sortie Pas specifique a API shortcode wordpress! Mais utile!
  22. Type de posts Un titre Du HTML Reset post data