Good day everyone, i am currently working on a php project and i want to be able to create short codes similar to that of wordpress.
Example: [welcome title="Welcome to our website" img="../example.jpg"]
the welcome message here
[/welcome]
result should be well formatted in a div element. Thank you.
Try looking at the Just Variables plugin for Wordpress.
You can store variables in the Admin and use them in your content (Posts and Pages) like this:
[justvars code="welcome-title"]
Or direct in your PHP code like this:
<?php just_variable("welcome-title"); ?>
Simple instructions and works really well!
Or, something that may be better suited to your question, is by simply creating a function.
function welcome_message () {
$welcome_message = "<div>This is your string</div>";
return $welcome_message;
}
And then you can call that function in your code by a simple echo statement:
<?php echo welcome_message(); ?>