Trying to find some confirmation on how this is possible within the confines of a plugin without success:
The goal is for a user to use a plugin that would insert a pre-defined snippet of code in a selected part of the layout. A typical use would be:
Included code appears below header
User selects "Above footer"
The "code" snippet would be something like a set of links, or an image. So that they could select from a drop-down menu, where it should appear on their site without editing any theme code.
I suppose it would also be useful to provide a tag that devs can paste somewhere in their theme template to be included somewhere more complicated, something like .
With a code file open in the editor, choose Snippets > Insert Snippet from the right-click menu, then My Code Snippets. You should see a snippet named Square Root. Double-click it. The snippet code is inserted in the code file.
In Wordpress, you can modify the output of the system in particular places, by using action hooks and filters. For instance:
function putSomeTextInTheFooter() {
echo '<p>This text is inserted at the bottom</p>';
}
add_action( 'wp_footer', 'putSomeTextInTheFooter' );
This PHP code, would modify the footer by adding a custom action [function], which Wordpress would fire right at the event called "wp_footer", which is self explanatory. There are hooks and filters for all kinds of things. Wordpress has a rich feature set for modifying just about everything. This kind of code can go in either a theme, or a plugin. Check out the codex here: https://codex.wordpress.org/Plugin_API/Action_Reference
Write a shortcode function in function.php
<?php
function test()
{
echo "I am test ";
}
add_shortcode("test_shortcode","test"); ?>
Now you can add [test_shortcode] any where in you editor to get the result there
Or in the template you can call it with
<?php echo do_shortcode([test_shortcode]); ?>
Hope this will help you to solve your problem
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With