Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Whats wrong with this WP php code?
Old 09-22-2009, 11:36 AM Whats wrong with this WP php code?
TWD
TWD's Avatar
King Spam Talker

Posts: 1,190
Trades: 0
I want to put a unique meta "description" on each page of my blog.

I have tried to install the following WP plugins
"Improved Meta Description Snippets"
"
Quick META Keywords"
"
Tags 2 Meta Generator"

but none of them will work for me.
So I tried this bit of custom code from:
http://darrenpangan.com/blog/dynamic...ress-blog.html
Code:
<meta name="description" content="<?php 
      if (is_single() || is_page()) {
           # Single post / page.
           # Use the 'description' custom field.
           echo get_post_meta($post->ID, 'description', true);
      } elseif (is_category()) {
          # Category page.
          # Use category's description
          echo trim(strip_tags(category_description()));
      } else {
          # Default meta description
          # Blog's description
          echo bloginfo('description');
      }
?>" />
Still doesn't work.
All I am seeing in the source code is:
Code:
<meta name="description" content="" />
I am running the
"All in One SEO Pack" and
"SEO Super Comments"
plugins as well.
They seem to be working fine except for not showing "description" or "keywords" meta tags.
Version is WP 2.8.4
TWD is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-22-2009, 12:18 PM Re: Whats wrong with this WP php code?
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
# has no meaning in PHP. Most likely the blog writer you refer to was using it as a placeholder, but should have been using // instead.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 09-22-2009, 12:26 PM Re: Whats wrong with this WP php code?
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Quote:
Originally Posted by NullPointer View Post
# has no meaning in PHP. Most likely the blog writer you refer to was using it as a placeholder, but should have been using // instead.
Unless it has been changed in some of the newer php versions (php 5 or later), the # character can indeed be used for single line comments, just as the double slash //.
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 09-22-2009, 12:37 PM Re: Whats wrong with this WP php code?
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by lizciz View Post
Unless it has been changed in some of the newer php versions (php 5 or later), the # character can indeed be used for single line comments, just as the double slash //.
My mistake. I'd never seen anyone use that syntax for comments before in PHP.


In that case I would make sure that the description is set, my guess is that it is just outputting the empty string because no description exists.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 09-22-2009 at 12:39 PM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 09-22-2009, 03:54 PM Re: Whats wrong with this WP php code?
jamestl2's Avatar
No scale-itch here...

Latest Blog Post:
Wordpress Relative URLs Plugin
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
Trades: 0
You'll probably need to place the string parameter into a variable, like this for example:
PHP Code:
<meta name="description" content="
<?php
$key
="description";
echo 
get_post_meta($post->ID$keytrue);  
?>
"/>
__________________
Engipress -
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
for Wordpress Projects
jamestl2 is offline
Reply With Quote
View Public Profile Visit jamestl2's homepage!
 
Old 09-22-2009, 07:18 PM Re: Whats wrong with this WP php code?
TWD
TWD's Avatar
King Spam Talker

Posts: 1,190
Trades: 0
Quote:
Originally Posted by jamestl2 View Post
You'll probably need to place the string parameter into a variable, like this for example:
PHP Code:
<meta name="description" content="
<?php
$key
="description";
echo 
get_post_meta($post->ID$keytrue);  
?>
"/>
I believe "description" is a custom WordPress field generated by the "All in One SEO" plugin.
TWD is offline
Reply With Quote
View Public Profile
 
Old 09-22-2009, 07:29 PM Re: Whats wrong with this WP php code?
jamestl2's Avatar
No scale-itch here...

Latest Blog Post:
Wordpress Relative URLs Plugin
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
Trades: 0
Isn't that what you named the field?

That's what the first statement of the if conditional represents, it assumes you typed some text into a custom "description" field on the edit post page.

It doesn't necessarily have to be generated by the SEO plugin, you can do it manually.
__________________
Engipress -
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
for Wordpress Projects
jamestl2 is offline
Reply With Quote
View Public Profile Visit jamestl2's homepage!
 
Old 09-22-2009, 09:03 PM Re: Whats wrong with this WP php code?
Junior Talker

Posts: 2
Name: Robert Truesdale
Trades: 0
I know this is going to sound stupid. But make sure you are putting your code into one of the .php files and not a post or created page.

And on some servers using <?php the server won't know what to do with that.
Try just using <? php code ?> as your php tags.
powerwebsites is offline
Reply With Quote
View Public Profile
 
Old 09-22-2009, 10:22 PM Re: Whats wrong with this WP php code?
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by powerwebsites View Post
I know this is going to sound stupid. But make sure you are putting your code into one of the .php files and not a post or created page.

And on some servers using <?php the server won't know what to do with that.
Try just using <? php code ?> as your php tags.
You've got that the wrong way around, using <? instead of <?php is not guaranteed to work.

Also, there is no indication that the code is not being parsed, only that the code results in no output. If it were the case that the code was not being parsed then the PHP source would appear in the HTML source.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 09-23-2009, 12:48 AM Re: Whats wrong with this WP php code?
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
The script must be fetching the descriptions and keywords from somewhere, like a database, a .txt file or set in a some other kind of config file. Are you sure you have set these values, or are they perhaps empty?
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 09-23-2009, 09:12 AM Re: Whats wrong with this WP php code?
racer x's Avatar
Ultra Talker

Posts: 457
Name: Randy
Location: Northern Wisconsin
Trades: 0
The only line that is really doing anything related to your unique meta description is:

echo get_post_meta($post->ID, 'description', true);

That is the magic of Wordpress Custom fields right there.

You have to create a field in the custom fields area on the page or post called "description". Then assign it the value of what you want the meta description to be. The other lines of code are simply either inputting the category description that you set when you created the category, or the overall blog description that you set in the admin Options area(i.e. just another blog)

If you are unsure how to use custom fields, see here:http://codex.wordpress.org/Custom_Fields
racer x is offline
Reply With Quote
View Public Profile Visit racer x's homepage!
 
Reply     « Reply to Whats wrong with this WP php code?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.85233 seconds with 12 queries