Custom Meta Property Per Category

Posted in: Newsmag
Post count: 23

Hello,

I have a list of categories with a list of meta properties that are specific per category.

Categories:
Peek Comedy
Peek History
Worthy Food

Meta Properties:
<meta property=”article:section” content=”comedy”/>
<meta property=”article:section” content=”history”/>
<meta property=”article:section” content=”food”/>

I am trying to get the correct meta properties on the pages according to the correct category. I am not the best at coding but I think I would use something like in_category or has_term to achieve this.

I also believe I need to put it on the single_template_x.php files. But I am having trouble with the exact code to achieve the right result. I also have some pages that have multiple categories and not sure how to handle this. Maybe just use the first/primary category and just show the meta property for that one.

Any help would be much appreciated! Thanks

Post count: 23312

Hello tcmc1313,

Please notice that the meta property is set from the td_wp_booster_functions.php as you can see here -> http://screencast.com/t/hZD2SyMlF0Z8 If you want to change the structure of these, please notice that is not a simple task and require to do some additional customizations and adjustments through the code that involves custom work. So, if you are not aware of the steps in this regard, please consider hiring a freelancer/developer to help you because we cannot provide customization services at the moment, sorry!

Thanks for your understanding!

Post count: 23

Is it not possible just to do something like this in the td_wp_booster_functions.php file:

if ( in_category( 'Peek Comedy' )) { echo '<meta property=”article:section” content=”comedy”/>';
} elseif in_category( 'Peek History' )) { echo '<meta property=”article:section” content=”history”/>';
} elseif in_category( 'Worthy Food' )) { echo '<meta property=”article:section” content=”food”/>';
}

Or am I missing something and it is much more difficult?

I am just trying to add these meta’s not change anything existing. Thanks!

Post count: 23

Oops, few coding errors I realized. Meant is_category and missed a few (

But in theory would it be something that simple or is there a lot of coding I would have to do?

Post count: 23

Looks like this did actually work for my issue. Placing the following code on td_wp_booster_functions.php


if ( in_category( '498' )) { echo '<meta property="article:section" content="comedy"/>';
} elseif ( in_category( '499' )) { echo '<meta property="article:section" content="history"/>';
} elseif ( in_category( '503' )) { echo '<meta property="article:section" content="food"/>';
}

Could have been some caching issues but using the actual ID (and of course fixing the bad coding) will now display my custom meta property per category.

Thanks for pointing me to the correct file!

Viewing 5 posts - 1 through 5 (of 5 total)
The forum ‘Newsmag’ is closed to new topics and replies.