Php and Javascript in Wordpress - a little assistance please?

5 replies
Warriors,

I am trying to put in a line of Javascript into the header information in Wordpress - but it's written in php.

I know I have to use the "echo" command and have been messing with it for 4 hours now.

Now - I'm just plain begging for help.

The code looks like this:

-----------------------------------------------------------
echo $output_line;

$seo_meta_tags = get_option( "gn_seo_meta_tags" );
if ( $seo_meta_tags == 'on' )
{
$seo_meta_desc = get_option( "gn_seo_meta_desc" );
$seo_meta_keyw = get_option( "gn_seo_meta_keyw" );
$seo_meta_author = get_option( "gn_seo_meta_author" );
$output_line =
' <meta name="keywords" content="' . $seo_meta_keyw . '" />' . "\n" .
' <meta name="description" content="' . $seo_meta_desc . '" />' . "\n" .
' <meta name="author" content="' . $seo_meta_author . '" />' . "\n";
echo $output_line;
}

---------------------------------------------------------------
That's just a small part of the header.php code and I am trying to insert a line of javascript sort of like this...

<script type="javascript"><src="http://whatever_source_is"></script>

Like I said - I have been at it for 4 hours or so and cannot get anything to work.

Any ideas?
#assistance #javascript #php #wordpress
  • Profile picture of the author BlackWaterBlog
    Maybe try this?

    echo $output_line;

    $seo_meta_tags = get_option( "gn_seo_meta_tags" );
    if ( $seo_meta_tags == 'on' )
    {
    $seo_meta_desc = get_option( "gn_seo_meta_desc" );
    $seo_meta_keyw = get_option( "gn_seo_meta_keyw" );
    $seo_meta_author = get_option( "gn_seo_meta_author" );
    $output_line =
    ' <meta name="keywords" content="' . $seo_meta_keyw . '" />' . "\n" .
    ' <meta name="description" content="' . $seo_meta_desc . '" />' . "\n" .
    ' <meta name="author" content="' . $seo_meta_author . '" />' . "\n" .
    ' <script type="javascript"><src="http://whatever_source_is"></script> ' . "\n";
    echo $output_line;
    }
    Signature

    {{ DiscussionBoard.errors[972007].message }}
  • Profile picture of the author SteveJohnson
    find a spot in the <head> section and paste your script code as-is. You'll want to stay out of the PHP sections. In other words, paste after the <head> tag, and before an opening <?php tag.

    You don't need to be in that section you posted the code to.

    If all else fails, PM me. We can fix this in a jif.
    Signature

    The 2nd Amendment, 1789 - The Original Homeland Security.

    Gun control means never having to say, "I missed you."

    {{ DiscussionBoard.errors[972021].message }}
  • Profile picture of the author Andy Fletcher
    <script type="javascript"><src="http://whatever_source_is"></script>
    I imagine this is just a mistake in typing it out here but just incase that should be -

    Code:
    <script type="javascript" src="http://whatever_source.js"></script>
    {{ DiscussionBoard.errors[972041].message }}
  • Profile picture of the author winebuddy
    Steve - the entire header.php file is in php

    There's no html in it - thats why I'm having such a hard time. Gonna try the fix above and then you may get a PM from me.

    Thanks!

    Blackwaterblog - thanks but it didn't work

    Steve - PM sent
    Signature
    "Knowledge is NOT power... ACTION on Knowledge is power"
    {{ DiscussionBoard.errors[972042].message }}
  • Profile picture of the author BlackWaterBlog
    You must have a strange theme then, would you mind posting the code up to the <body> tag?

    Don't think I've ever seen a WP theme with full php code for the header information before.

    Here's a little preview of my theme header.php;

    Signature

    {{ DiscussionBoard.errors[972066].message }}

Trending Topics