WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#6686 closed enhancement (invalid)

New Feature: insert header & footer snippets

Reported by: Mrasnika Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Template Keywords: header, footer
Focuses: Cc:

Description

One of the problem than I encounter when working w/ Wordpress and changing themes, is that I often miss to add the header/footer HTML snippets, which are in general either some sort of site-wide widgets like snap.com, or some web counter/tracker, or some meta tags like the Google/Yahoo webmasters verification meta tag. I miss them, because I have added them to the old version of the themes, and I forget to add them to the new ones.

To deal with this, I have created a simple plugin (see attached). I utilizes the wp_header/wp_footer template tags to insert the HTML snippets. The great thing about it, is that the snippets are going to be inserted no matter which theme you are using. I know that there are several plugins similar to that, like the plugin that inserts the Google Analytics code, but I haven't stumbled upon a more uniform solution.

Anyway, I see great potential for this as a core WordPress feature, because almost all of the blogs have some sort of HTML snippets inserted. Please take a look at the attached plugin as a proof of concept and tell me what you think.

Attachments (1)

hefo.php (4.6 KB) - added by Mrasnika 6 years ago.

Download all attachments as: .zip

Change History (15)

Mrasnika6 years ago

comment:1 markjaquith6 years ago

Is there a way that Widgets could be made to fill this role?

comment:2 jhodgdon6 years ago

Mark - In my opinion, it is doubtful that Widgets could be used here. Or that they would be all that appropriate. Especially for the header -- wp_head() and the wp_head action actually go into the HTML head section, not the body section, so only things like meta tags and such can be inserted there, not things that will actually appear on the screen (which is what Widgets are. I think that most people also wouldn't want something as complex as most of the widgets in the bottom of their page footer either -- more likely it's a copyright notice, a link to some plugin that made your site possible, etc.

That said, it might be possible to set up some common things people would want to add (plain text and links for footer; meta tags and link tags, and ??? for the header), in a manner similar to Widgets, but I think these would be two completely separate lists of items from the Widgets used on the sidebar. So probably on a separate Design page.

comment:3 follow-up: zamoose6 years ago

Or leave it to the theme authors to add to their functions.php (my preferred solution and one that I tend to use myself).

comment:4 zamoose6 years ago

Clarifying my statement -- add a textarea labeled "Footer Credits" or somesuch and allow folks to fill it out as needed.

comment:5 follow-ups: jhodgdon6 years ago

The point the request submitter here was making is that there are some items that may be theme-independent for the header and footer, so you want to be able to enter them in one place, and have them inserted into any theme you might activate. So you don't want to leave it to the theme, because then when you activate a new theme you will have to enter the same information again.

I think (not sure) that happens with Widgets, doesn't it? If you switch themes, your widgets stay active (assuming the new theme also supports Widgets)? Same idea here...

comment:6 in reply to: ↑ 5 ionfish6 years ago

Replying to jhodgdon:

I think (not sure) that happens with Widgets, doesn't it? If you switch themes, your widgets stay active (assuming the new theme also supports Widgets)? Same idea here...

That really depends how the theme author has implemented widgets; if they use names for their 'sidebars' that differ from the default then they won't be cross-theme (and they'll stop the user from selecting one-use widgets elsewhere). This is something that could really use some work, but obviously it's something of a separate issue.

comment:7 in reply to: ↑ 5 xenlab6 years ago

Replying to jhodgdon:

The point the request submitter here was making is that there are some items that may be theme-independent for the header and footer, so you want to be able to enter them in one place, and have them inserted into any theme you might activate. So you don't want to leave it to the theme, because then when you activate a new theme you will have to enter the same information again.

Indeed. +1 for this feature. I will play with the plugin and see if it fits the bill, but this is functionality that should be theme independent for sure.

comment:8 follow-up: darkdragon6 years ago

That is an interesting design. I've also used it plenty of times, however, you are still creating an instance of a class when an instance is not needed.

Instead of:

new hefo();

How about:

hefo::init();

In this way, since the method call is static, the reference to the object does not need to be made.

However, in the init() method, you will have to initialize the object, since you don't use static method calls either. I would suggest using static method calls:

Instead of:

array(&$this, 'methodname')

try this instead:

array('classname', 'methodname')

You take a considerable hit using the first one, but the second is almost as fast as the function call.

comment:9 in reply to: ↑ 3 Mrasnika6 years ago

Replying to zamoose:

Or leave it to the theme authors to add to their functions.php (my preferred solution and one that I tend to use myself).

function.php is a file for each theme, so putting this functionality in a theme is the exact opposite of what my suggestion is. My goal is to make those header/footer HTML snippets theme-independent, so they will be persistent no matter what theme you use.

comment:10 in reply to: ↑ 5 Mrasnika6 years ago

Replying to jhodgdon:

I think (not sure) that happens with Widgets, doesn't it? If you switch themes, your widgets stay active (assuming the new theme also supports Widgets)? Same idea here...

That's exactly what happens w/ widgets, as long as the theme is widgets-aware ;)

comment:11 in reply to: ↑ 8 Mrasnika6 years ago

Replying to darkdragon:

Thanks for the advice, indeed an instance here is not needed.

comment:12 follow-ups: westi6 years ago

  • Milestone 2.7 deleted
  • Resolution set to invalid
  • Status changed from new to closed

The wp_head and wp_footer hooks already make it simple to write a plugin to contain your theme-independent customisations.

Storing these customisations in the database just seems like a waste.

comment:13 in reply to: ↑ 12 strider726 years ago

Replying to westi:

The wp_head and wp_footer hooks already make it simple to write a plugin to contain your theme-independent customisations.

Storing these customisations in the database just seems like a waste.

With respect, I think that sort of misses the point. This is meant for the non-programmer.

However, as it readily works as a plugin, there is no burning need for it to be in core. That is, nothing is lost by not having it "always available".

So... I guess I agree with your conclusion (not needed in core), but not your reasoning.

Actually, there is an advantage to this not being "always available" as part of core: lazy plugin authors would probably use it, even though it _isn't_ meant for them. So in that sense there is a specific advantage to leaving this as a plugin, that is actually _lost_ by making it core.

Great plugin, though. I'll probably use it myself!

comment:14 in reply to: ↑ 12 Mrasnika6 years ago

Replying to westi:

The wp_head and wp_footer hooks already make it simple to write a plugin to contain your theme-independent customisations.

Storing these customisations in the database just seems like a waste.

The point of this feature is to make it easier for the non-programmers to deal with persistent, theme-independent header/footer HTML snippets. Anyway, thanks for the comments

Note: See TracTickets for help on using tickets.