Native function to add code to Head

General questions relating to Joomla! 2.5. Note: All 1.6 and 1.7 releases have reached end of life and should be updated to 2.5. There are other boards for more specific help on Joomla! features and extensions.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
Locked
Azrael
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 102
Joined: Wed Aug 02, 2006 1:37 am

Native function to add code to Head

Post by Azrael » Thu Jul 31, 2014 2:11 pm

Hi,

Can anyone tell me the native Joomla function to add code to the head of the page? I need it to add custom open graph tags. Thanks advance.

User avatar
jbuzzeo
Joomla! Intern
Joomla! Intern
Posts: 58
Joined: Tue Jul 29, 2014 1:25 am
Location: Wilmington - South Eastern North Carolina - USA
Contact:

Re: Native function to add code to Head

Post by jbuzzeo » Thu Jul 31, 2014 6:06 pm

there are several extensions that claim to handle this in the JED -> http://extensions.joomla.org/

I don't actually have experience with any of them, but it's a place to start
Jason Buzzeo - Follow me on Google+
http://www.ParadigmCustomSolutions.com - Custom web development for organizations big and small
^- Specializing in Joomla 2.5 & 3.0

User avatar
jackrabbit
Joomla! Ace
Joomla! Ace
Posts: 1473
Joined: Thu May 21, 2009 3:12 am
Location: Florida
Contact:

Re: Native function to add code to Head

Post by jackrabbit » Thu Jul 31, 2014 9:23 pm

There is no native function for OG tags though there is for http-equiv and name (http://docs.joomla.org/JDocument/setMetaData)

Use a plugin from the list at http://extensions.joomla.org/extensions ... open-graph or add these lines to the head php tag of index.php

Code: Select all

$app = JFactory::getApplication();
$document = JFactory::getDocument();
$og	= '<meta property="og:title" content="'.$document->title.'" />' ."\n";
$og .= '<meta property="og:type" content="Magazine" />' ."\n";
$og .= '<meta property="og:url"  content="'.rtrim(JURI::base(), '/').$_SERVER["REQUEST_URI"].'" />' ."\n";
$og .= '<meta property="og:image" content="'.JURI::base().'images/ogimages/default.png" />' ."\n";
$og .= '<meta property="og:site_name" content="'.$app->getCfg('sitename').'" />' ."\n";
$og .= '<meta property="fb:admins" content="65745237346832" />' ."\n";

$document->addCustomTag($og);
Last edited by jackrabbit on Thu Jul 31, 2014 9:29 pm, edited 1 time in total.
Reset Joomla super user password and username simply | http://cmsenergizer.com/website-energy- ... d-remotely

Azrael
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 102
Joined: Wed Aug 02, 2006 1:37 am

Re: Native function to add code to Head

Post by Azrael » Thu Jul 31, 2014 9:27 pm

Actually what I need is a function to add code to the head of the page. I know how to add og tags, but I want a function that will inject a custom code (where I have all the og tags) to the head of that page.

User avatar
jackrabbit
Joomla! Ace
Joomla! Ace
Posts: 1473
Joined: Thu May 21, 2009 3:12 am
Location: Florida
Contact:

Re: Native function to add code to Head

Post by jackrabbit » Thu Jul 31, 2014 10:02 pm

$document->addCustomTag($og); will add the code to the head. Other head functions are
addStyleSheet()
addStyleDeclaration()
addScript()
addScriptDeclaration()
setMetaData()

and many more. Your original question specifically said you want to add custom OG tags and that is what the code I laid out will allow. Otherwise you will need to layout a precise and sensible explanation of your ultimate goal.
Reset Joomla super user password and username simply | http://cmsenergizer.com/website-energy- ... d-remotely

Azrael
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 102
Joined: Wed Aug 02, 2006 1:37 am

Re: Native function to add code to Head

Post by Azrael » Thu Jul 31, 2014 10:15 pm

I apologize for not being more precise. I'll try to explain it in detail. Are you familiar with the jReviews extension?

User avatar
jackrabbit
Joomla! Ace
Joomla! Ace
Posts: 1473
Joined: Thu May 21, 2009 3:12 am
Location: Florida
Contact:

Re: Native function to add code to Head

Post by jackrabbit » Thu Jul 31, 2014 10:40 pm

I know of it but have never used it.
Reset Joomla super user password and username simply | http://cmsenergizer.com/website-energy- ... d-remotely

Azrael
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 102
Joined: Wed Aug 02, 2006 1:37 am

Re: Native function to add code to Head

Post by Azrael » Fri Aug 01, 2014 12:53 am

I'm using it for music. It allows you to add custom fields to each listing (which works as a joomla article) and one of those fields I insert several OG tags together.

So I need a function which will tell jReviews to send the data on that custom field to the head of the page, to include those OG tags.

User avatar
jackrabbit
Joomla! Ace
Joomla! Ace
Posts: 1473
Joined: Thu May 21, 2009 3:12 am
Location: Florida
Contact:

Re: Native function to add code to Head

Post by jackrabbit » Fri Aug 01, 2014 1:28 am

Well now you are outside the Joomla core. It is neither general or new to joomla. This should have been posted in the forum relative to extensions http://forum.joomla.org/viewforum.php?f=620
Reset Joomla super user password and username simply | http://cmsenergizer.com/website-energy- ... d-remotely


Locked

Return to “General Questions/New to Joomla! 2.5”