I've got a wordpress website and tried to insert the following code in my head element to display an individual meta description for a custom post type taxonomy called "all-cars" but in won't work:
<?php if( is_tax('all-cars') ) { ?>
<meta name="description" content="text text text" />
<?php } ?>
Could somebody give me some advice?
Related
I create a post category and sub category then add to menu now i want to echo some specific data for each specific category page but i can not find the source file in theme directory.
I also use firebug inspect element but it show only html help me to find exact php source file thanks.
Here is my code.
<?php
$current_user = wp_get_current_user();
if ( is_category( 'nokia' ) ) {
echo "<h1> i am iqbal</h1>"
?>
<h1> i am iqbal </h1>
<!-- HTML markup here -->
<?php } else { ?>
<h1>
i am not iqbal
</h1>
<!-- other HTML markup here -->
<?php } ?>
I'm migrating custom wordpress templates over from an old site to a new site. In the new site one of my older templates using ACF Repeater is generating unnecessary < p > breaks between each element in my echo. Here's the source code:
<?php
if( have_rows('features_list') ):
$i=0;
while ( have_rows('features_list') ) : the_row();
echo '<p><span class="purple">+ </span>' . get_sub_field('feature_item') . '</p>';
$i++;
endwhile;
endif;
?>
The rendered HTML comes out to:
<p>
<span class="purple">+ </span>
</p>
<p>Text Content Text Content</p>
What I need it to render as and what it was in my old template is:
<p><span class="purple">+ </span> Text Content Text Content</p>
Im suspecting that Wordpress is wrapping my get_sub_field() in a < p > and therefore is closing the < span > around a < p > because of the wpautop() function. Im running Wordpress 4.5.3 and seeing this.
This has been resolved. The solution was in the Custom Fields dashboard within the specific subfield. There is an option for "New Lines" conditional formatting and by default it was set to "Automatically add paragraphs". I switched it to "none" and this fixed the problem.
Thanks
I want to show limit latest post of WordPress in main page. I'm using WordPress APIs and functions to show that, but after that get_the_content() remove and escape all of seved tags and my posts don't show correctly such as editor tags.
This function escape HTML tags:
<ul style="list-style: none;margin:5px" class="latest-posts">
<!-- LOOP START -->
<?php $the_query = new WP_Query( 'showposts=3' ); ?>
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<!-- THIS DISPLAYS THE POST THUMBNAIL, The array allows the image to has a custom size but is always kept proportional -->
<li> <?php the_post_thumbnail( array(100,100) );?></li>
<!-- THIS DISPLAYS THE POST TITLE AS A LINK TO THE MAIN POST -->
<li>
<a href="<?php the_permalink() ?>">
<?php the_title(); ?>
</a>
</li>
<!-- THIS DISPLAYS THE EXCERPT OF THE POST -->
<li>
<?php echo mb_substr(get_the_content(), 0, 1200).' ...'; ?>
</li>
<!-- READ MORE LINK -->
<li>more ...</li>
<?php endwhile;?>
<!-- LOOP FINNISH -->
</ul>
There are basically three possibilities how to output the excerpt of the post content.
with the excerpt() function, to output the content of the excerpt field in post editor, if it's not filled it will display the first 55 words of the post content ( use excerpt_length filter to control the length of the excerpt ).
to use the <!--more--> quicktag, the_content() tag will only show the excerpt up to the <!--more--> quicktag. That quicktag will not work in single pages templates.
to manually strip HTML from post content and to show custom excerpt. One way to do that is to use wp_filter_nohtml_kses() function:
echo mb_substr( wp_filter_nohtml_kses( get_the_content() ), 0, 1200 );
All methods above will strip the HTML from post content. To include HTML in excerpts use excerpt field in post editor, WordPress will preserve HTML you included in post editor. There are also some plugins like Advanced Excerpt that will create excerpt from content and preserve html, but I don't believe that there is a bullet proof way of doing that.
I have a Wordpress custom Meta Field and I want to display only those fields that have a value in it ( and not display those where the user has not put a value).
How I can go about doing this?
Just wrap your code to display in if condition:
<?php if (get_post_meta(get_the_ID(), "field_name", true)): ?>
<!-- here your html & meta echo or-->
<?php echo get_post_meta(get_the_ID(), "field_name", true) ?>
<?php endif; ?>
I am trying to create an overview function using colorbox in WordPress.
Let me explain a little. In WordPress, pages have posts that are queried through this code:
$lastposts = get_posts( $args );
foreach($lastposts as $post) : setup_postdata($post);
get_template_part( 'content', get_post_format() );
endforeach;
So this will grab all the posts that are in the WordPress database. Now each post is a product, so I want to know if there is a way I can add some code to this to have a value set to each post that, once someone clicks on the post image it will send the title of that post so it can grab an overview template (something I will make) of that specific product.
UPDATE:
Here is the jQuery that opens once any image is clicked:
<link media="screen" rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/js/colorbox.css" />
<script src="<?php echo get_template_directory_uri(); ?>/js/jquery.colorbox-min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function()
{
$('.item-post a').colorbox({opacity:0.3, href:"../overviewa512454dzdtfa"});
});
</script>
I want the title of the post the image is associated with sent to the file that is opened in colorbox.
I would put a rel="<?= $post['title'] ?>" in your links, so that each link has the post title. (Sorry if $post['title']" isn't the right attribute for the WP Post, but you'll find that). Then, in your javascript, pass the title in the URL, like:
<script type="text/javascript">
$(function()
{
$('.item-post a').bind('click',function() {
event.preventDefault();
var product_title = $(this).attr('rel');
colorbox({opacity:0.3, href:"../overviewa512454dzdtfa?title=" + product_title});
});
});
</script>
You should either URL encode the title you're passing inside the rel=" tag, or do it with javascript when you pass it to the colorbox.
Then, the overview page, you can access the title with $_REQUEST['title'].
content-page.php, content-aside.php, etc., are the files used in your WP theme to output your products in your loop, because of this line in your code :
get_template_part( 'content', get_post_format() );
So basically, all you need to do is to open these files and in the part that outputs the content of each post, surround the post image with an achor using the ID of your post (<a href="#" id="post-<?php the_ID(); ?>">...
Then you will easily be able to "target" the appropriate overview using the ID in your jQuery query...