Hi,
Is it possible to create head section titles and meta descriptions using Toolset.? If so how, are there any example snippets?
Thanks for any help
Hello,
What kind of header section do you want?
If you are using Blocks editor, you can use Toolset heading block to display text in heading format, and set the data source from current post's custom fields, see my screenshot heading.jpg
See our document:
https://toolset.com/block-item/heading/
If you want more customized styles, please try container block:
https://toolset.com/course-lesson/container-blocks/
Thanks Luo,
Don't see screenshot heading.jpg.
I have the following View Loop:
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<div class="comp-grid">
<div class="hdr">
<p class="med-cmp-tit">
Medicinal Complaints / Uses
</p>
<p style="margin-left: 25vw" class="outlined">
[wpv-post-taxonomy type='botanical-name' format='name']
</p>
</div>
<div class="comp-tbl">
<table style="table-layout: auto;"> <!-- style="table-layout: auto;" -->
<tr>
<th>System/State</th>
<th>Traditional <br> Complaint/Use</th>
<th>
Activity / Interpretation
[tooltips content="Terms used (<a href='glossary2/#activity 'target='_blank'>see Glossary</a>) are an interpretation of activity only. They have not been validated for this website and are <b>NOT</b> intended as scientific evidence or recommendation for use. (See also <a href='disclaimer/ 'target='_blank'>DISCLAIMER</a>)"]
<i class="fas fa-info-circle fa-info-icon" style="margin-top: -3vh"></i>
[/tooltips]
</th>
<th>Traditional <br> Preparation/ Administration</th>
<th>
Parts Used
[tooltips content="<a href='glossary2/#parts' target='_blank'>See Glossary</a> for explanation of plant parts"]
<i class="fas fa-info-circle fa-info-icon"></i>
[/tooltips]
</th>
<th>
Source
[tooltips content="<b>Z</b> = Zaitschek collection (Natural Medicine Research Center),<br/> <b>B</b> = BERC (Biodiversity & Environmental Research Centre).<br/> <b>Z, B</b> = Species described in both data sets"]
<i class="fas fa-info-circle fa-info-icon"></i>
[/tooltips]
</th>
</tr>
<tbody class="wpv-loop js-wpv-loop">
<wpv-loop>
<tr>
[wpv-post-body view_template="loop-item-in-complaints-list-new-table"]
</tr>
</wpv-loop>
</tbody>
</table>
</div>
</div>
[/wpv-items-found]
[wpv-no-items-found]
<strong>[wpml-string context="wpv-views"]No Medicinal Complaints or uses found for this species[/wpml-string]</strong>
[/wpv-no-items-found]
[wpv-layout-end]
and the Template for this View - Loop item in complaints list new table :
<td class="only-first-system-cf">[types field="system-cf"][/types]</td>
<td>[types field="complaint-use-cf"][/types]</td>
<td>[wpv-post-taxonomy type="action-medicinal" format="name"]
<td>[types field="prep-admin"][/types]</td>
<td>[wpv-post-taxonomy type="part-used" format="name"]
<td>[types field="source-cf"][/types]</td>
What I need to do is collect all the
[types field="complaint-use-cf"][/types]
from the table and insert the column
as a paragraph into the header section Meta Description. Possibly some "complaint-use-cf" fields contain punctuation.
How do you suggest I do this.
Thanks for your help.
Thanks for the details, in your case, you can only display the post information within View's loop, the "complaint-use-cf" fields are part of post information, so you can not display them outside View's loop.
As a workaround, you can setup another post view, use same query filters, in view's loop, output those "complaint-use-cf" fields information, and display this post view in the "header section Meta Description".
Thanks for this, so I now have this View: Complaints List Meta Desc
[wpv-layout-start]
<ul>
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>
[wpv-post-body view_template="loop-item-in-complaints-list-meta-desc"]
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
</ul>
[wpv-no-items-found]
[wpml-string context="wpv-views"]No Medicinal Complaints or uses found for this species[/wpml-string]
[/wpv-no-items-found]
[wpv-layout-end]
and
The "Loop item in Complaints List Meta Desc"
<li>[types field="complaint-use-cf"][/types]</li>
How do I insert this meta description into the head section.
Also I have another requirement, I need to limit the size of each
output to a maximum of the first 3 words to ensure maximum meta description size is not exceeded , how would I do this
Thanks for your help
Q1) How do I insert this meta description into the head section.
It depends on your website(theme) settings, if the "head section" is defined in your theme file, you can use Views function render_view() to display the new post view, see our document:
https://toolset.com/documentation/programmer-reference/views-api/#render_view
Q2) I need to limit the size of each
There isn't such kind of built-in feature within Toolset plugins, you can create a custom shortcode:
https://developer.wordpress.org/reference/functions/add_shortcode/
And output specific limited size of string, for example:
https://developer.wordpress.org/reference/functions/wp_trim_words/
Hi Luo, tried following your instructions - without success.
I have the Yoast (not premium) installed and inserted the view slug in meta description - see attached screenshot - but when I view a page source I see:
<!-- Admin only notice: this page does not show a meta description because it does not have one, either write it for this page specifically or go into the [SEO - Search Appearance] menu and set up a template. -->
What am I doing wrong?
Thanks for your help.
I'm using Generate Press theme which supports adding meta description.
This is an example:
add_action( 'wp_head', function() {
if ( is_singular() ) {
$meta_title = get_post_meta( get_the_ID(), 'your_meta_title_custom_field', true );
$meta_desc = get_post_meta( get_the_ID(), 'your_meta_description_custom_field', true );
if ( $meta_title ) {
printf( '<meta name="title" content="%s">', $meta_title );
}
if ( $meta_desc ) {
printf( '<meta name="description" content="%s">', $meta_desc );
}
}
} );
How would I include the output from View complaints-list-meta-desc.
Thanks
It is out the range of Toolset support, Toolset Views is designed to work in content area.
I suggest you check it with Generate Press support for: How to output content in their meta area.
Then use render_view() function to output views results.
Or you can setup your custom PHP codes with WordPress function get_posts() directly:
https://developer.wordpress.org/reference/functions/get_posts/
Retrieves an array of the latest posts, or posts matching the given criteria.