0

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');
?>

Edited by Latrell_vie

2
Contributors
2
Replies
30
Views
5 Months
Discussion Span
Last Post by Latrell_vie
2

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”

Edited by jkon

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.