GetSimple Support Forum
SOLVED Plugin to add META tag to header - Printable Version

+- GetSimple Support Forum (http://get-simple.info/forums)
+-- Forum: GetSimple (http://get-simple.info/forums/forumdisplay.php?fid=3)
+--- Forum: Plugins (http://get-simple.info/forums/forumdisplay.php?fid=13)
+--- Thread: SOLVED Plugin to add META tag to header (/showthread.php?tid=16122)



Plugin to add META tag to header - David Singleton - 2021-02-19

It is recommended to add the following META tag to the HTML header, so that the content is better displayed on a mobile device.


Code:
<meta name="viewport" content="width=device-width, initial-scale=1.0">

The question is: how to do this in Get-Simple?

I have found a way using a simple plugin, as follows:
Code:
<?php
/*
Plugin Name: Innovation Theme Settings
Description: Adds a META tag to the HTML header
Version: 1.2
Author: David Singleton
Author URI: -
*/

# get correct id for plugin
$thisfile_name=basename(__FILE__, ".php");

# register plugin
register_plugin(
    $thisfile_name,                                 # ID of plugin, should be filename minus php
    'HeaderMetaTagPlugin',                             # Title of plugin
    '0.1',                                             # Version of plugin
    'David Singleton',                                # Author of plugin
    '',                                             # Author URL
    'Inserts a meta-tag in the HTML header',         # Plugin Description
    'theme',                                         # Page type of plugin
    'theme_header'                                  # Function that displays content
);

# and add an action for it
add_action ('theme-header', 'theme_header', array (false));

function theme_header() {
    # Insert tag: <meta name="viewport" content="width=device-width, initial-scale=1.0">   
    # Recommendation from https://www.w3schools.com/css/css_rwd_viewport.asp
    echo ("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">");
}

?>

The plugin should be installed in the 'plugins' directory. The plugin registers an action 'theme-header', which is then called automatically from the Get-Simple framework. The result is the required, inserted META tag.


RE: Plugin to add META tag to header - datiswous - 2021-02-22

Easier is just putting that line in the website theme.

But kudos that you made a plugin for it. I guess it's also a nice example plugin, for people that like to learn making plugins.

Btw. if theme already has this line in it, it would be doubled, right? So then there should be a check if the line exist or not (if statement?).