Header And Footer: How To Use The Init Configuration

On version 1.3.7 released today there is a new important options on Header and Footer plugin dedicated to coders who need to add small function to blogs without modify the used theme. This options is a piece of PHP code that can be added on Header and Footer configuration and that will be executed on plugin initialization.

An example is the definition of a short code without installing a plugin. Suppose you need to give to a customer a simple short code to embed something on specific posts or pages, for example an iframe. A non technical customer won’t be able to add it with the raw WordPress editor, even if it’s possible. For a generic editor is simpler to use a short code, like [ myiframe ] and learn that this piece of text will be replaced with special content.

So, how can you define “on the fly” that short code? Specifically, how can you avoid to define it on function.php theme so it will be theme independent? On Header and Footer init options, just add:

add_shortcode(‘myiframe’, ‘myiframe_callback’);

function myiframe_callback($attrs, $content) {
return ‘<iframe src=”…” width=”…” height=”…”></iframe>';
}

This way you’ll be able, later, to change the code, maybe for formatting needs without reopening every post.

And is this short code should not produce content at some point in the future? You shouldn’t remove it, otherwise the short code will appear on posts where it is used: you can change the code this way:

function myiframe_callback($attrs, $content) {
return ”;
}

This option has many other usages, of course, and you can contribute leaving a comment!


My excuses for my bad english but it's the only way I have to communicate with you. Would you suggest a correction? Leave a comment, thank you!

5 thoughts on “Header And Footer: How To Use The Init Configuration

  1. Radulph

    Dear Stefano,

    thank you a lot for your helpful plugin. Trying days to solve the the problem to get scripts from the header to the footer now it is my question how can I do it without your plugin?

    In the header I hav for example
    <script src="/scripts/suckerfish.js” type=”text/javascript”>
    <script src="/scripts/jquery.min.js” type=”text/javascript”>

    What is the code to put it into the footer.php? wp_footer is included. I think I have to do this in the function.php…

    I’m asking because I want to see that this can be done…

    Sorry for my bad English,
    Radulph

  2. Rodrigo

    Hi!

    The problems with this new update when you save the changes to the settings of the plugin. The plugin lets the User without access to the administration panel of wordpress. When trying to access returns the message “page not found (404).” Please check a solution urgently.

    Thank you!

    1. Rodrigo

      Please ignore the first comment.

      There is a serious problem with the new update. After saving changes to the settings of the plugin it lets the User without access to the administration panel of wordpress. When trying to access returns the message “page not found (404).” Please check a solution urgently.

      Thank you!

      1. Stefano Post author

        Probably the code you write in the init configuration generates a serious error. I made an update so the init is executed only under some circumstances (if possibile).

Leave a Reply