StudioPress Community Forums
  StudioPress Community Forums > Forums > General Discussion
For help and support, access to your downloads, or to manage your account please log into My StudioPress.

These forums have been set to read-only so you can browse the existing topics for any questions you may have.

For general discussion on WordPress, CSS and design (NOT for support) visit the new Community Forums.
 
 
Thread Tools Display Modes
  #1  
Old 09-22-2012, 09:48 AM
crazyforcrust crazyforcrust is offline
Registered User
Genesis Member
 
Join Date: Aug 2012
Posts: 5
Default Javascript in post & custom fields

I am trying to add a sponsor code to a post. The html they gave me is in javascript, and the editor keeps stripping the script from my post when I switch between html and visual.

I know that there is a chance, if I put the html into my post and immediately publish, that it will show up, but I need to know for sure that the content will show before I publish as this is a sponsored post.

I have searched (a lot) about this issue and it seems it is a regular problem with wordpress. I am wondering if I enter the code via a custom field, if the javascript will show up?

Now, I figured out how to make the custom fields show in the post editor. I *think* I figured out how to add a custom field.

The html I need to add to my post is:

<p>
<script type="text/javascript" src="http://thirdparty.fmpub.net/placement/515381?fleur_de_sel=[timestamp]"></script>
</p>
This post is sponsored by <a href="http://r1.fmpub.net/?r=http%3A%2F%2Fad.doubleclick.net%2Fclick%3Bh%3Dv 2%7C3FC7%7C0%7C0%7C%252a%7Cq%3B261384384%3B1-0%3B0%3B82742153%3B31-1%7C1%3B50321305%7C50305898%7C1%3B%3B%3Bpc%3D%5BTP AS_ID%5D%253fhttp%3A%2F%2Fwww.verybestbaking.com%2 Frecipes%2F144809%2FDark-Chocolate-Brownies%2Fdetail.aspx&k4=4891&k5={banner_id}"targ et="blank">Nestlé® Toll House® Morsels</a>, the perfect special ingredient for all of your family’s favorite treats!

In the post, I went to the custom fields section and added a new custom field called "nestle" with that code as the value.

At this point I am stuck because I have no idea what to do next.

Here is a screenshot of what the custom field looks like:


I think I need to add some code somewhere else? Or something? I am a complete novice and am very scared of entering anything in my .php file without expert opinion.

I have read several of the "help" articles on wordpress...but they are all written talking about codes and such and I have no clue.

Please help, I really need to make sure this code and the image is in my post.

My url is: http://www.crazyforcrust.com

Thank you!
  #2  
Old 09-22-2012, 01:10 PM
NicktheGeek's Avatar
NicktheGeek NicktheGeek is offline
Forum Manager
 
Join Date: Feb 2010
Posts: 62,650
Default

here is a pretty good tutorial showing a simple way to do that
http://vividvisions.com/2009/02/11/w...-to-your-post/

You will have to edit your functions.php file
__________________
Nick "Fred and/or George Weasley" Croft
Designs by Nick the Geek
@Nick_theGeek on Twitter

Make web design easier, get FireBug for FireFox

Want to learn more about Genesis? Check out my Genesis Explained Series

  #3  
Old 11-08-2012, 09:48 AM
Benjamyne Benjamyne is offline
Registered User
Genesis Member
 
Join Date: Feb 2011
Posts: 34
Default

I've tried adding that code to the php file but after i save the changes the editor fails to complete loading and so does not even show that the php file was saved successfully.
It appears the changes are causing problems because the wordpress dashboard, the page and the entire website doesn't load but just shows a blank page.

I had to undo the changes via FTP

I simply pasted the code into the php file and added // before it because it seemed everything on the file started with it.
This is what the file looked like code is in Blue,

<?php
// Start the engine
require_once(TEMPLATEPATH.'/lib/init.php');

// Child theme library
require_once(CHILD_DIR.'/lib/custom-header.php');
require(CHILD_DIR.'/lib/style.php');

// Child theme (do not remove)
define('CHILD_THEME_NAME', 'Lifestyle Theme');
define('CHILD_THEME_URL', 'http://www.studiopress.com/themes/lifestyle');

// Add support for custom background
if ( function_exists('add_custom_background') ) {
add_custom_background();
}

// Add new image sizes
add_image_size('Mini Square', 70, 70, TRUE);
add_image_size('Square', 110, 110, TRUE);

// Force layout on homepage
add_filter('genesis_pre_get_option_site_layout', 'lifestyle_home_layout');
function lifestyle_home_layout($opt) {
if ( is_home() )
$opt = 'content-sidebar';
return $opt;
}

// Add advertising code after single post
add_action('genesis_after_post_content', 'lifestyle_include_adsense', 9);
function lifestyle_include_adsense() {
if ( is_single() )
require(CHILD_DIR.'/adsense.php');
}

// Add two sidebars underneath the primary sidebar
add_action('genesis_after_sidebar_widget_area', 'lifestyle_include_bottom_sidebars');
function lifestyle_include_bottom_sidebars() {
require(CHILD_DIR.'/sidebar-bottom.php');
}

// Add support for 3-column footer widgets */
add_theme_support( 'genesis-footer-widgets', 3 );

// Customize the footer section
add_filter('genesis_footer_creds_text', 'lifestyle_footer_creds_text');
function lifestyle_footer_creds_text($creds) {
$creds = __('Copyright', 'genesis') . ' [footer_copyright] [footer_childtheme_link] '. __('on', 'lifestyle') .' [footer_genesis_link] &middot; [footer_wordpress_link] &middot; [footer_loginout]';
return $creds;
}

// function field_func($atts) {
global $post;
$name = $atts['name'];
if (empty($name)) return;

return get_post_meta($post->ID, $name, true);
}

add_shortcode('field', 'field_func');


// Register widget areas
genesis_register_sidebar(array(
'name'=>'Sidebar Bottom Left',
'id' => 'sidebar-bottom-left',
'description' => 'This is the bottom left column in the sidebar.',
'before_title'=>'<h4 class="widgettitle">','after_title'=>'</h4>'
));
genesis_register_sidebar(array(
'name'=>'Sidebar Bottom Right',
'id' => 'sidebar-bottom-right',
'description' => 'This is the bottom right column in the sidebar.',
'before_title'=>'<h4 class="widgettitle">','after_title'=>'</h4>'
));
genesis_register_sidebar(array(
'name'=>'Featured Top Left',
'id' => 'featured-top-left',
'description' => 'This is the featured top left column of the homepage.',
'before_title'=>'<h4 class="widgettitle">','after_title'=>'</h4>'
));
genesis_register_sidebar(array(
'name'=>'Featured Top Right',
'id' => 'featured-top-right',
'description' => 'This is the featured top right column of the homepage.',
'before_title'=>'<h4 class="widgettitle">','after_title'=>'</h4>'
));
genesis_register_sidebar(array(
'name'=>'Featured Bottom',
'id' => 'featured-bottom',
'description' => 'This is the featured bottom section of the homepage.',
'before_title'=>'<h4 class="widgettitle">','after_title'=>'</h4>'
));
  #4  
Old 11-08-2012, 02:54 PM
NicktheGeek's Avatar
NicktheGeek NicktheGeek is offline
Forum Manager
 
Join Date: Feb 2010
Posts: 62,650
Default

// comments the text, so that is what broke it. You could put // on the line before with a short description of what that does.
__________________
Nick "Fred and/or George Weasley" Croft
Designs by Nick the Geek
@Nick_theGeek on Twitter

Make web design easier, get FireBug for FireFox

Want to learn more about Genesis? Check out my Genesis Explained Series

  #5  
Old 11-10-2012, 08:54 AM
Benjamyne Benjamyne is offline
Registered User
Genesis Member
 
Join Date: Feb 2011
Posts: 34
Default

I have edited the functions file successfully but now I don't know where to go.
I thought I'd see a custom field appear below the area for the post content marked custom field but I don't see one.

According to this article on WordPress, it's hidden by default until used for the first time but I can't find where to create it. http://codex.wordpress.org/Custom_Fields

I'm doing this so I can enter a dynamic javascipt banner in the post area.
  #6  
Old 11-10-2012, 10:25 AM
NicktheGeek's Avatar
NicktheGeek NicktheGeek is offline
Forum Manager
 
Join Date: Feb 2010
Posts: 62,650
Default

Click "screen options" in the top right corner of the page/post editor. Make sure custom fields are enabled there.
__________________
Nick "Fred and/or George Weasley" Croft
Designs by Nick the Geek
@Nick_theGeek on Twitter

Make web design easier, get FireBug for FireFox

Want to learn more about Genesis? Check out my Genesis Explained Series

  #7  
Old 11-11-2012, 08:07 AM
Benjamyne Benjamyne is offline
Registered User
Genesis Member
 
Join Date: Feb 2011
Posts: 34
Default

Thanks that worked.
As for the javascript banner, I've been moving round in circles, I need help again.

Since I'm trying to add a banner, what are the next steps I should take?

I added a new custom field with the name as PBBanner and pasted the code into the value field.

I thought i had to add something to the post but none my attempts worked.
The best result was just some empty box in the area where the banner should have been
What should I do to add the banner to the post?
  #8  
Old 11-11-2012, 09:55 AM
NicktheGeek's Avatar
NicktheGeek NicktheGeek is offline
Forum Manager
 
Join Date: Feb 2010
Posts: 62,650
Default

[field name="PBBanner"]
__________________
Nick "Fred and/or George Weasley" Croft
Designs by Nick the Geek
@Nick_theGeek on Twitter

Make web design easier, get FireBug for FireFox

Want to learn more about Genesis? Check out my Genesis Explained Series

  #9  
Old 11-11-2012, 11:26 AM
Benjamyne Benjamyne is offline
Registered User
Genesis Member
 
Join Date: Feb 2011
Posts: 34
Default

So it was the quotation marks that was missing!
It's now working.
Thank you.
  #10  
Old 11-11-2012, 09:12 PM
NicktheGeek's Avatar
NicktheGeek NicktheGeek is offline
Forum Manager
 
Join Date: Feb 2010
Posts: 62,650
Default

You're welcome.

Since this is resolved I'm going to close this thread.
__________________
Nick "Fred and/or George Weasley" Croft
Designs by Nick the Geek
@Nick_theGeek on Twitter

Make web design easier, get FireBug for FireFox

Want to learn more about Genesis? Check out my Genesis Explained Series

 

Tags
custom fields, javascript

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 12:31 AM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.