Questions tagged [template-tags]

Template tags are custom WordPress-specific functions for use in theme template files.

0
votes
0answers
11 views

How To Display The Latest Updated Date Conditionally

I have been trying this for hours and just not getting it, any help would be highly appreciated. I am creating a code in template tags to show the last modified date on my WordPress website, so far it ...
0
votes
1answer
377 views

How can I include custom category and tag base in template files?

How can I include custom category and tag base names in the category and tag template files? Specifically, I'd like to include in the page title of category and tag pages the custom category and tag ...
0
votes
1answer
32 views

How to display a custom taxonomy without a link?

I need to display the name of a custom taxonomy term in a page template, and I've tried with the following line: <h2><?php the_terms( 0, 'my_category'); ?></h2> This correctly ...
1
vote
1answer
37 views

Edit css for search results page

I have a search results page with a template call content-search.php. Basically what this file does is to display the results after a person searches something on the search bar, and i would like to ...
1
vote
2answers
1k views

Exclude a category from the_category in the single post page

I want to include something like the the_category function in a WordPress post, which by default echoes a list of links to all categories the post is attached separated by comma, but I want to exclude ...
1
vote
1answer
12 views

WordPress menu link doesn't work properly

I am developing custom site. The header links work on home-page but when I go inside shop then the home-link becomes siteurl/shop how to solve this? <div id="content" class="site-content"> &...
0
votes
1answer
19 views

Show the section only if custom taxonomy was chosen

So I have a code where all items of my custom taxonomy ('colour') are displayed. I broke my head trying to show the section ("colour__chart") only if one of taxonomy items was chosen. In simple words, ...
1
vote
1answer
155 views

'is' functions and 'get_query_var' not working

Why does is functions not work inside an Ajax function? Except for is_user_logged_in? I also tried using get_query_var and it did not work. jQuery: jQuery('.post-modal').live('click', function(e) { ...
1
vote
1answer
14 views

Please help me to figure out how to display my tags

desperately looking for help. Have a Wordpress theme which does not display post tags on a single page and I badly need to have them there. Developers only named a file which needs to be modified. It'...
0
votes
0answers
37 views

Pagination doesn't work in query post in tag template

In tag template I use the following query post: global $query_string; // required $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; ...
0
votes
1answer
40 views

using themename_the_custom_logo() in template-tags?

I am trying to learn how to create a theme for wordpress so i looked at the default theme 'twenty sixteen'. I was crawling around it and searching everything that i find strange then i saw this code ...
0
votes
1answer
46 views

Limit Tag Links in Post Content

I am trying to Limit Maximum Numbers of Tag Links to appear within post content. Below is my code. I don't know how to fix it up. function link_words( $text ) { $replace_times=3; $replace = ...
0
votes
1answer
17 views

Show author image at home page latestest posts plugin

On my home page, I'm showing the last 3 blog posts with their respective titles, texts and their featured images. I need to change the featured image at homepage to each blog to the image of the ...
5
votes
2answers
3k views

How to get the clean permalink in a draft?

When I use the_permalink or get_the_permalink in a draft or scheduled post, the URL provided is not the "final" permalink—it is the unpretty ?p=xxxxx version. How can I get the final, "clean" ...
0
votes
0answers
62 views

method to fetch entire tag list on archive.php

What I have Tried → <?php $taginto = get_the_tag_list(); if ( ! empty( $taginto ) ) { echo '<a class="categum" href="' . esc_url( get_tag_link( $taginto[0]->term_id ) ) . '">' ...
1
vote
2answers
759 views

Disable Woocommerce product tags display by alphabetical order

I have a Woocommerce e-shop where each product has at least five tags. The problem is each product's tags are displayed alphabetically on the single product page. I would like to know if it's ...
0
votes
1answer
4k views

is_front_page and is_home are not working in page.php

I'm trying to target my landing page with is_front_page or is_home in my page.php file but it's not working. I have set the settings > reading to a static page. However, if I create a page-home....
1
vote
1answer
23 views

Sort list of page templates a-z?

In the code below, it possible to sort the results alphabetically - and if so what changes do I need? <?php $templates = get_page_templates(); foreach ( $templates as $template_name => $...
10
votes
3answers
14k views

Echo author ID in author.php

This is probably a super simple question. But how do I echo the ID of a user on author.php? I've tried the_author_meta('ID') But it didn't seem to want to work. I want to echo it at the end of a ...
5
votes
1answer
2k views

get_parent_theme_file_path vs. get_template_directory

I've been reading about the new functions for referencing theme location added in v4.7. I read through the trac ticket. I understand why they created these functions and the benefit of ...
0
votes
1answer
58 views

How to modify template tags function?

By default, get_user_meta returns an array, a single value or false. I want to change the return value somehow. How to do that? I want to modify the return type of a template tag get_user_meta inside ...
0
votes
0answers
28 views

Template tags not working in the customizer preview

I have a small code to inject some CSS to the single post. And it has an option in the Customizer to enable/disable the CSS. My code is similar to this: add_action( 'wp_head', function() { if ( ! ...
0
votes
2answers
126 views

php within html within php

I use an extension called Custom Field Suite to import info from a csv in order to batch create posts. In order to display the form fields I use <?php echo CFS()->get('image_location'); ?> ...
1
vote
3answers
86 views

different tag different stylesheet

i have tags, and for some tags i want to load a different stylesheet But i don't know how i have.... function customstyles() { if ( is_tag( 'circulair' ) ) { //Register and enqueue the ...
0
votes
2answers
35 views

Template Tag Does Not Work in Page Template

I've created a page template and used this code to call a post which contains a shortcode: $post_id = 129; if( get_post_status( $post_id ) == 'publish' ) { the_content(); } The problem is that ...
0
votes
1answer
103 views

How do I str_replace with template tag?

I have a template tag of: <?php echo the_post_thumbnail( 'full' ); ?> It outputs: <img src="/graphics/magazine/802/1.jpg" class=" wp-post-image" alt="" /> I want to remove 'class=" wp-...
-1
votes
1answer
41 views

Misleading information in the Codex, how do they get away with it? [closed]

I'm new to WordPress Development but I've programmed in PHP for a couple of years. My understanding is that the Codex pages are as close to authoritative information on WordPress that you're going to ...
1
vote
1answer
392 views

setup_postdata is not returning any values

I am using ACF to create a custom field called facilities. Within that field is a repeater field called facility. So each store has 'facilities', which contains a number of 'facility'. What I am ...
1
vote
3answers
568 views

How to check if I am inside the WP Theme Customizer preview?

I have some elements showing on the home page that I do not want to display in the Theme Customizer preview window. Is there a simple check in PHP that I can use for that ? For example: <img ...
0
votes
4answers
990 views

Function to echo (or display?) wordpress tags in the head section

I can't figure this out but I'm trying to echo the post Tags of the post in the <head> section. This code resides in the <head> section of the site. Basically I want the post tags to ...
1
vote
1answer
89 views

Changing Image Size In The Content tag

I am developing a WordPress theme locally and I can't figure out how to get an image to display in a normal size in the_content(). At the moment, the images are displaying the same size as my featured ...
0
votes
1answer
39 views

showing tag beside catagory

thanks for your guidance, here is one last but not least thing for me to learn, i am using Today news wordpress theme, since with your help i have moved my process from category to tag based ...
0
votes
1answer
93 views

Wordpress tag or archive php file customization

I am not that pro with php but i have good concept and can find my way in cleverly, this forum have always put me ahead of the game due to people like you who share as the care, I have a site that ...
3
votes
3answers
3k views

Remove line breaks in wp_list_categories()?

I am trying to output a list of categories per an article. I am using the following code, <?php wp_list_categories('child_of=270&style=none'); ?> (string) Style to display the categories ...
0
votes
0answers
112 views

edit_post_link returns blank

I'm using edit_post_link in The Loop and the function keeps returning the $before and $after arguments with blank content. <?php edit_post_link('edit', '<p>', '</p>'); ?> returns &...
0
votes
0answers
698 views

Hide Certain Tags on Single Post Page

I'm trying to hide certain tags from single posts pages. I've googled and found 2 codes but both are hiding the whole post page. I'm using a theme that needs using 2 tags ticker and slider to show ...
0
votes
1answer
162 views

How do I get shortcode, widget and template tag CSS to load in the head only as required? [duplicate]

I have a shortcode, widget and template tag that need to load CSS. I am registering in init, and enqueueing as required. The only problem is, it is adding the CSS loader at the bottom of the page, ...
0
votes
1answer
1k views

Calling the first & last post by category in custom post type

I have custom post type for comics, called “comic” and have written a basic comic navigation. First —previous — (current) title — next — and last comic. In functions.php, this code calls for the ...
1
vote
4answers
12k views

Multisite get_home_url(); - Getting URL for current site

What would be the replacement for get_home_url() when using a multisite? For example, if I have one theme installed across several sites, and within the theme there are links that need to be specific ...
0
votes
0answers
248 views

'Post_tag' taxonomy tags don't link to existing posts in CMS

I'm using this bit of code to retrieve the object data for post_tag taxonomy. <?php $tax = 'post_tag'; $tax_terms = get_terms($tax); if ($tax_terms) { foreach ($tax_terms as $...
0
votes
0answers
116 views

Get list of body classes for X page?

Is there a way to grab the list of body classes for X page? I tried: <?php get_body_class('home'); ?> but got a console error for function not defined.
7
votes
2answers
19k views

why doesn't the_content() work in this {single-custom_post_type.php} page?

This code is from my page single-publication.php. It outputs the relevant custom fields etc (here wrapped in template tags), but the_content() won't output the post content. I've resorted to using $...
0
votes
1answer
1k views

Getting custom post type author and date published

In underscores I can get my custom post type just fine with pre get posts along regular blog posts. However the date published and author does not display. How can I modify my template tag (...
1
vote
1answer
281 views

Is there a way to display a menu using the ol tag instead of the default ul tag?

I'm trying to display a menu using wp_nav_menu(). The default markup that the function generates is a menu parented by a <ul> tag like so: <ul> <li><a>Menu 1</a></...
0
votes
2answers
3k views

Displaying list of subcategories and not parent category

I have a blog which has three top level categories. Each top level category has a list of sub categories. I am displaying only certain top level category posts in certain sections of the website. ...
0
votes
1answer
52 views

Custom Fields Question

I'm new to wordpress and I am trying to understand these custom fields. I read the wordpress codex page refering to custom fields but I have some questions. I take for example my site. I created a ...
0
votes
1answer
2k views

the_category() tag not styling HTML or CSS

I am having problems getting my the_category() template tag to style accordingly with the rest of my theme. I believe this is because the HTML isn't output the same way as the the_author() and ...
0
votes
2answers
67 views

comments_number fails to print

I want to display the number of comments on a post using the template tag <?php comments_number( $zero, $one, $more ); ?> However, for some reason this tag does nothing and it is ...
1
vote
1answer
8k views

Get permalink and title by post name?

In the theme there is a custom post type called faq I just want to get certain post by its name (NOT by id cause no id exist). <?php query_posts('post_type=faq') ?> how to get the_tile() and ...
2
votes
1answer
5k views

Wordpress function/template tag to get first n words of the content

OK, this might be a duplicate, I was just unable to put my idea in proper search terms, sorry for that! Is there a built-in function or template tag to get the first n words of the content? I mean ...