Adding a gettexed element after the category term
-
After “Lignano Pineta” (category name, top-left of the page) I’d like to add “case vacanze” (holiday apartments) using an english gettexed name. “Lignano Pineta case vacanze” will also appear in the breadcrumbs as a consequence. Could I simply modify my custom_add_count_on_archive_title ($ title) function adding something to this line?
$title .= ' '.$total_count.'';-
This topic was modified 1 year, 1 month ago by
sacconi.
The page I need help with: [log in to see the link]
-
This topic was modified 1 year, 1 month ago by
-
I got a first result using:
$title .= ' '. esc_html__( "holiday apartments", "sacconicase" ) . ' '. $total_count.'';but is it correct also from the formal point of view? Now about the second goal, adding the same text in the breadcrumbs, I thought I could “hack” the language filter function…
Hi @sacconi ,
Your query is about whether modifying the custom function is enough or not. I’m afraid that without knowing the full code, what I could comment on is limited. Could you please share the full code so that we can have a better idea?
Regards,
Nithin
The second function I should modify is: https://pastebin.com/SCJNr5qm
I just have to have a gettexed text in the current page breadcrumbs term, i.e. in this page https://test.sacconicase.com/case-vacanza/italia/friuli-venezia-giulia/lignano-sabbiadoro-appartamenti-vacanze/ you should read “Lignano Sabbiadoro case vacanza” instead of simply “Lignano Sabbiadoro”…
And this is the code I modified to have a custom gettexed text in the post count function: https://pastebin.com/5NCcEnhU
Hi sacconi,
is it correct also from the formal point of view?
If it accomplishes what you want, then it’s fine.
adding the same text in the breadcrumbs, I thought I could “hack” the language filter function…
That’s unlikely to work since taxonomy terms aren’t normally translated via gettext. The breadcrumb trail is from Breadcrumb NavXT, isn’t it? There may be a filter that can be used to alter term titles, such as
"get_{$taxonomy}"where $taxonmy is any specific taxonomy. If the taxonomy is “category”, the filter name would be “get_category”.The requested WP_Term object is passed to your callback. You can set the object’s
$nameproperty to be anything you want. Then Breadcrumb NavXT will presumably use whatever name you’ve set. (unconfirmed)I have the following as a filter for the beadcrumbs: https://pastebin.com/kSeGRU78
maybe I can add some gettext both to $title and $title_lang ? My addition problem is that the added text is only on the current page beadcrumb term, so if (in italian) I want to add “case vacanza”, the result shouldnt be Home case vacanza > Italia case vacanza> Friuli Venezia-Giulia case vacanza> Lignano Sabbiadoro case vacanza, but just Home > Italia > Friuli Venezia-Giulia > Lignano Sabbiadoro case vacanza
so just the last term in the trail would receive the addition
Adding gettext will not solve the problem. If ‘bcn_breadcrumb_title’ filter does not let you alter a particular breadcrumb, you’ll likely need to rely on related WP filters like “get_category” or “the_title”. The right filter depends upon the nature of any particular breadcrumb item.
So I have to inspect first the plugin files? there are many files in the plugin folder…
Yes, but they don’t all need to be inspected. The goal is to find a usable filter hook in the code that’s responsible for a particular breadcrumb element. It is almost certainly in one of the breadcrumb classes, of which there are only two possible files to inspect. Your search is made easier if you search the code for
apply_filters. This function orapply_filters_ref_arrayhas to be used in order for there to be an available breadcrumb filter.If no suitable filter is found, then you really do need to find the exact code responsible for a particular breadcrumb element’s output. Determine what WP function is used to get the element, such as get_term() or get_post(). Those WP functions likely have a filter in which the element’s name can be altered as desired.
Maybe here there is something interesting for me?
/**
* Assembles the parts of the breadcrumb into a JSON-LD ready object-array
*
* @param int $position The position of the breadcrumb in the trail (between 1 and n when there are n breadcrumbs in the trail)
*
* @return array(object) The prepared array object ready to pass into json_encode
*/
public function assemble_json_ld($position)
{
return (object) apply_filters('bcn_breadcrumb_assembled_json_ld_array', array(
'@type' => 'ListItem',
'position' => $position,
'item' => (object)array(
'@id' => esc_url($this->url),
'name' => esc_attr($this->title))
), $this->type, $this->id);
}
}That may be part of a complete solution, but I’m skeptical. JSON-LD is for structured data that’s not visible to end users, it’s to help search engines better classify the page. It’d be unusual for the visible breadcrumbs to take their titles from JSON-LD, yet it’s still a remote possibility.
You could try altering the passed ‘name’ field to see if this filter has any effect at all. It doesn’t look like this feature is even active, the only JSON-LD markup on the linked page is from Yoast.
In relation to one of your other recent topics:
You’re using the add_meta_boxes hook for posts, you need to alter it to be for products:
add_action( 'add_meta_boxes_product', "title_en_add_meta_box" );It works, thank you! I also added a multilanguage locale-based filter, the same as for sacconicase.com, and it works, now I should filter the “short description” field for “product” custom post-type, but I have no place to open the topic. Also at woocommerce forum they told me it’s out of their mission the php developing…
The topic ‘Adding a gettexed element after the category term’ is closed to new replies.