Hi ! I´m developing my first wordpress plugin. To create a shortcode according to tutorial i should duplicate following code. But why is it function form_creation(){ ?> instead of function form_creation(){} ?> I mean why is only a part of function form_creations curled bracket inside the php ending tag ? I think i used to know the concept , but even googling didnt refresh my memory. What is the reason behind this ? Thx

<?php
/*
* Plugin Name: WordPress ShortCode
* Description: Create your WordPress shortcode.
* Version: 1.0
* Author: InkThemes
* Author URI: https://inkthemes.com
*/

// Example 1 : WP Shortcode to display form on any page or post.
function form_creation(){
?>
<form>
First name: <input type="text" name="firstname"><br>
Last name: <input type="text" name="lastname"><br>
Message: <textarea name="message"> Enter text here...</textarea>
</form>]
<?php
}
add_shortcode('test', 'form_creation');
?>

PHP isn't complex . Everything outside PHP tags will consider it as direct output. Let's see an example :

<?php 
function hello()
{
    echo "hello";
}
hello();
?>

Is the same as:

<?php 
function hello()
{
?>
    hello
<?php 
}
hello();
?>

And some more about that. PHP as many languages (as Java) first translate the code in a format that their engine will recognize (in case of PHP that is opCodes) and then will execute it (as the engine understands it) in demand. Even if you have a PHP file named anything.php with only in it:

hello

That will be translated to opCodes @see http://php.net/manual/en/internals2.opcodes.php .
In the anything.php example above those opCodes are really minimal and they only say to output “hello”

jkon thank you , very clear and good explanation !

commented: happy to assist +9
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.