WordPress – Plugin to include snippet of code into selected parts of the layout

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:

Read More
  • User selects “Below header”
  • Included code appears below header

  • User selects “Above footer”

  • Included code appears 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 .

Related posts

3 comments

  1. 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

  2. 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

  3. You are looking for register_sidebar function.

    You can create named sidebar area with this function and put any widgets to it from Apperarence -> Widgets (in wp-admin). In your theme files you can call dynamic_sidebar in place you want, and all widgets will be appeared in this place.

Comments are closed.