Stap 5: Maak een Shortcode
OK dus de volgende voegt een shortcode aan WordPress om weer te geven of de Instructables robot of HELLO WORLD.
Shortcode functie die is aangeroepen. U kunt argumenten gebruiken om te configureren hoe of wat wordt teruggegeven.
functie idw_HelloWorldShortCode ($args, $content = null)
{
$a = shortcode_atts (array
('img' = > 'waar',
), $args);
$returnValue = '';
Als ($a ["img"] == 'true')
{
$returnValue = 'img url';
}
anders
{
$returnValue = 'HELLO WORLD';
}
Return $returnValue;
}
Shortcode actie die roept de functie hierboven en voegt de shortcode in WordPress.
Gebruikt door het plaatsen van [idwHelloWorld idw = "true"] of [idwHelloWorld idw = "false"] in een pagina of post.
add_shortcode ('idwHelloWorld', 'idw_HelloWorldShortCode');