wordpress category page: Custom meta description - php

I'm using wordpress, and I'm trying to create custom descriptions for categories pages.
I have modified its header.php file to echo custom titles and descriptions. But Wordpress is replacing my meta description with that of first post.
How can I stop this?
My Code:
echo '<meta name="description" content="'.$desc.'" />';
I'm using eMovies Theme: http://fthemes.com/emovies-free-wordpress-theme/
My site category link: http://www.raagalu.in/category/telugu-songs/
I even tried using plugins like "Category SEO Meta Tags", but no use. It is just creating two meta descriptions.
Please help me fix this.

<?php single_cat_title(); ?>
If you are on a category or template page.
See http://codex.wordpress.org/Function_Reference/single_cat_title

Related

Can I change the contents of a description meta tag generated by Yoast in a WordPress site?

I am quite new to WordPress so I am not sure how this would work.
Essentially I have the Yoast plugin handling my SEO related things. The main one giving problems is the description meta tag.
The site is bilingual and I would like the description meta tag to be translated as well. Yoast currently does not provide that option, unless I get another plugin which I do not want to get into.
As it stands, I am told that I can insert the description meta tag through the functions.php using add_action. This unfortunately does not work as it only adds another description meta tag.
Currently my code looks like this:
function insert_meta_tag_in_head () {
echo '<meta name="description" content="My New content" />';
}
add_action('wp_head', 'insert_meta_tag_in_head', 1);
So basically this just gives me a second description meta tag. I have also seen in other threads, that if I want to replace a tag, I should use the do_action function. Which I call as follows:
do_action('wp_head', 'insert_meta_tag_in_head');
This however does nothing.
What am I doing wrong? How can I change the contents of the description tag given to me through Yoast?
We've previously changed a Yoast title before, however, a description is something we have been working on too.
To sum-up the link above:
You need to filter the wpseo_metadesc action in order to display your
new description.
add_filter('wpseo_metadesc', 'new_desc_function');

Remove page count from WooCommerce search page title

When navigating to the next page of search results in Woocommerce, the title shows as
Search results: “example” – Page 2
I would like to know how I can customise this so the page number is not shown. Ideally, it would be nice to be displayed as
Search results for Example
I have looked in the files and this title seems to be called using
<?php woocommerce_page_title(); ?>
So there's not much there for me to work on.
There are lots of posts on removing the title all together, nothing on how to customise it.
You can use woocommerce_page_title hook to alter the title
according to your need.
Here is a working code:
// define the woocommerce_page_title callback
function filter_woocommerce_page_title($page_title)
{
if (is_search())
{
$page_title = 'Search results for ' . ucfirst(get_search_query());
}
return $page_title;
}
// add the filter
add_filter('woocommerce_page_title', 'filter_woocommerce_page_title', 10, 1);
Code goes in functions.php file of your active child theme (or theme). Or also in any plugin php files.
Hope this helps!

Adding Image to custom woocommerce Taxonomy with ACS

I added a custom taxonomy called "Topics" to woocomerce products and Now i would like to add an image to each Topic and have it shown on the page of that Topic.
I am trying to use Advanced Custom fields plugin but I do not know where to the the ACF php code.
Any help would be greatly appreciated.
Advanced Custom Fields Example Link Here https://www.advancedcustomfields.com/resources/code-examples/
get the ACF image filed in Taxonomy
<?php
$products_category_object = get_queried_object();
$product_category_taxonomy = $products_category_object->taxonomy;
$product_category_term_id = $products_category_object->term_id;
$category_acf_image = get_field('your ACF Image Field name', $product_category_taxonomy.'_'.$product_category_term_id);
echo "<pre>";
print_r($category_acf_image);
echo "</pre>";
?>
<img src="<?php echo $category_acf_image['your url key']; ?>" />
There is a plugin Custom Category Image available in wordpress to do that.
This plugin will add option to add image file for each category/taxonomy.
As specified in the plugin description use following code to get the image anywhere in your code -
MGC_Custom_Category_Image::get_category_image($term_id, $size);

Add a meta description for a custom post type archive in WordPress

Here's my issue :
I have a WordPress site where I created a custom post type (named "collections") with an article for each collection.
I'd like to add a meta description to the archive page of the custom post type
www.thesitename.com/collections
I have tried with this bit in header.php :
<?php
if (is_category('collections'))
{
?>
<meta name="description" content="the description">
<?php } ?>
but there's nothing in the source code...
I have looked everywhere in Yoast SEO but I can't find a solution, not even on google.
Do you have ideas ?
If you want to check post_type archive page then you have to use
is_post_type_archive() and if you want to check the archive page of
custom post_type category then you have to use is_tax()
if (is_post_type_archive('collections'))
{
echo 'This is the collections post_type archive page';
}
Addition info but not directly related to your question.
if (is_tax('collections_cat', 'cat-1'))//<-- Replace it with your taxonomy, term name
{
echo 'This is the collections post_type, category cat 1 archive page';
}
Hope this helps!
Wordpress is written in PHP, which means that HTML like that will not work by itself. It is for this reason that in most tracking codes are established by including something along the lines of <?php include_once("analytics.php"); ?>
In your case, you would have to echo any HTML elements like this. Like so:
<?php if (is_category('collections')) {
echo"<meta name='description' content='the description'>";
}
?>

Changing title of dynamic page in Wordpress

Does anyone know of a way to change the title of a page that is created dynamically in Wordpress? The pages in question are created dynamically via a plugin, and do not appear in the list of pages or Wordpress SEO in the admin section.
Here is an example of a page I would like to change the title of: http://www.forestlakechevrolet.com/inventory/New/
The inventory tool is maintaining the inventory of two dealerships, but only one is featured on this site. So it uses an SEO title based on the makes available at both dealerships.
Essentially, I am wondering if there is a function that I could add that would say "If URL is ... then force page title to be ***."
Does anyone know how to do this?
Thank you,
Jared Wilcox
Just use the wp_title filter
Add something like this to your theme's functions.php file:
<?php
function assignPageTitle( $title ){
global $post;
if ($post->post_name === "test") {
$title = "Title goes here";
}
return $title;
}
add_filter('wp_title', 'assignPageTitle');
?>
You may also need to change your theme's header file if the wp_title call is adding the Site Name.
BTW, WordPress questions are better asked on https://wordpress.stackexchange.com/

Categories