the link of the product tab appears 2 characters / - css

I am using WCFM plugin. Everything works fine, there is only one problem that I have not solved yet, that is the link of the product tab appearing 2 // characters, and it is wrong with some other functions on my web.
Here is the screenshot
all other tabs are fine, only the product tab appears 2 characters / as below.
ex: mydomain.com/store/storename//#tab_links_area
And I want it to turn into the following
mydomain.com/store/storename/#tab_links_area
or: mydomain.com/store/storename/product/#tab_links_area
And I have checked that the code that affects this place is in store-tabs.php file of WCFM plugin as follows
<?php do_action( 'wcfmmp_store_before_tabs', $store_user->get_id() ); ?>
<div id="tab_links_area" class="tab_links_area">
<ul class="tab_links">
<?php foreach( $store_tabs as $store_tab_key => $store_tab_label ) { ?>
<li class="<?php if( $store_tab_key == $store_tab ) echo 'active'; ?>"><?php echo $store_tab_label; ?></li>
<?php } ?>
</ul>
</div>
<div class="wcfm-clearfix"></div>
<?php do_action( 'wcfmmp_store_after_tabs', $store_user->get_id() ); ?>
I don't know anything about code, can you help me fix this issue using CSS or using code to insert to function.php in my child theme.
I am very grateful and look forward to your feedback

It seems like the store link is register with a "/" at the end in the database whereas the others are not. Maybe there was a change in the permalink structure between the creation of product page and the other pages.
First thing you can do is to go to settings->permalinks and click the "save changes" to make sure all your links will have the same structure.
If this not solve your issue, you can handle it with your code.
You can test if the last caracter of the string that contains your pages link "$store_user->get_store_tabs_url( $store_tab_key )" end up with a "/" and if it the case delete it before it is used in the anchor tag.
So, in those lines =>
<?php foreach( $store_tabs as $store_tab_key => $store_tab_label ) { ?>
<li class="<?php if( $store_tab_key == $store_tab ) echo 'active'; ?>">
<?php echo $store_tab_label; ?>
</li>
<?php } ?>
you should add the test and have something like that :
<?php foreach( $store_tabs as $store_tab_key => $store_tab_label ) { ?>
<li class="<?php if( $store_tab_key == $store_tab ) echo 'active'; ?>">
<?php
/* Get the link */
$tab_link = $store_user->get_store_tabs_url( $store_tab_key );
/* If the link end up with "/" */
if(substr($tab_link, -1) == "/"){
$tab_link = substr_replace($tab_link ,"",-1); // Delete the last caracter.
}
?>
<?php echo $store_tab_label; ?>
</li>
<?php } ?>

Related

How to display posts with plugin (advanced custom fields) field groups?

I have a php/wordpress code (present inside abc.php file) as shown below which displays images of particular size.
php/wordpress (inside abc.php file):
<ul id="list-thumbs" class="list-grid">
<?php
while ( have_posts() ) : the_post();
?>
<li class="list-grid__thumb shows-grid__item">
<a class="list-grid__img-link" href="<?php echo esc_url( get_the_permalink() ); ?>" tabindex="0">
<?php if ( has_post_thumbnail() ) { ?>
<?php
$image_id = get_post_thumbnail_id( get_the_ID() );
WORLD\Images\the_img_fit_figure( $image_id, 'list-grid__image', '(min-width: 450px) 50vw, 70vw', false ); ?>
<?php } ?>
</a>
</li>
<?php endwhile; ?>
</ul>
The code above displays around 30-40 images from top to bottom with 4 images in one row.
(a) All of those images are featured image in wordpress associated with a post of post_type hello-world
(b) Every post has two fields, Row View (in_row_view) and Column View (in_column_view) coming from Advanced Custom Fields plug in. I am not sure if we can call those two fields as custom fields.
(c) Row View and Column View both are switch which can be enabled to Yes or No. By default, it is set to No.
(d) For Row View, I am using:
if(get_field('in_row_view' ) == '1'){ }
For Column View, I am using:
if( get_field('in_column_view' ) == '1'){ }
What I want to achieve is I want to display those posts which have Row View switch enabled to Yes.
Problem Statement:
I am wondering what changes I need to make in the php/wordpress code above so that it displays only those posts which have Row View switch enabled to Yes.
Probably I need to integrate this code if(get_field('in_row_view' ) == '1'){ } in the php/wordpress code above.
Quick/Sloppy Solution:
<ul id="list-thumbs" class="list-grid">
<?php
while ( have_posts() ) : the_post();
// This will skip the loop
if(get_field('in_row_view' ) != '1') { continue; }
?>
<li class="list-grid__thumb shows-grid__item">
<a class="list-grid__img-link" href="<?php echo esc_url( get_the_permalink() ); ?>" tabindex="0">
<?php if ( has_post_thumbnail() ) { ?>
<?php
$image_id = get_post_thumbnail_id( get_the_ID() );
WORLD\Images\the_img_fit_figure( $image_id, 'list-grid__image', '(min-width: 450px) 50vw, 70vw', false ); ?>
<?php } ?>
</a>
</li>
<?php endwhile; ?>
</ul>
... the issue with the "Quick Solution" is that it will not render the desired "posts per page". The easier way is to include or exclude at the query level with meta_query ... this can be done by grabbing the query "in flight" with the pre_get_posts hook.
The More Elegant Solution
function pw_filter_query( $query ) {
// Your conditions for NOT applying the meta query ... use wp conditionals! :)
if( !$query->get('post_type') != 'your_post_type ) { return $query; }
$query->set('meta_key', 'ecpt_color');
$query->set('meta_value', 'green');
}
}
add_action('pre_get_posts', 'pw_filter_query', 9999);
Source Reference

Remove Page Header from Blog Posts

I have a page-header that is getting copied over to all of my blog posts that I want to remove completely. I am removing it visually via CSS, but SEO crawlers are still picking it up via the tag.
I am using a standard wordpress them augmented with Elementor. Here is a screenshot of the SEO report.
And here is a screenshot of the actual HTML code
Let me know if any of you have any additional questions! Thank you for your help!
You can make a conditional statement that just outputs the title of the post if on single blog posts, so something like this
<div class="container clr page-header-inner">
<?php
// Return if page header is disabled
if ( oceanwp_has_page_header_heading() ) { ?>
<!-- check to see if single blog posts -->
<?php if (is_single()) : ?>
<h1><?php echo get_the_title(); ?></h1>
<!-- otherwise show the existing title format -->
<?php else: ?>
<<?php echo esc_attr( $heading ); ?> class="page-header-title clr"<?php oceanwp_schema_markup( 'headline' ); ?>><?php echo wp_kses_post( oceanwp_title() ); ?></<?php echo esc_attr( $heading ); ?>>
<?php endif; ?>
<?php get_template_part( 'partials/page-header-subheading' ); ?>
<?php } ?>
<?php if ( function_exists( 'oceanwp_breadcrumb_trail' ) ) {
oceanwp_breadcrumb_trail();
} ?>
</div><!-- .page-header-inner -->
you would have to replace the existing code

Get Wordpress Featured image form external RSS feed

I used the following code in my FUNCTIONS file:
add_action('rss2_item', 'add_my_rss_node');
function add_my_rss_node() {
global $post;
if(has_post_thumbnail($post->ID)):
$thumbnail = get_attachment_link(get_post_thumbnail_id($post->ID));
echo("<image>{$thumbnail}</image>");
endif;
}
Now I try to call that image and display it from site A to my site B with a custom RSS tempalte. This is the code of the template.
<?php get_header(); ?>
<?php include_once(ABSPATH.WPINC.'/feed.php');
$rss = fetch_feed('https://notrealurl.net/categoryname-feed/');
$maxitems = $rss->get_item_quantity(30);
$rss_items = $rss->get_items(0, $maxitems);
?>
<ul>
<?php if ($maxitems == 0) echo '<li>No items.</li>';
else
// Loop through each feed item and display each item as a hyperlink.
foreach ( $rss_items as $item ) : ?>
<li>
<a href="<?php echo $item->get_permalink(); ?>">
<?php echo $item->get_title(); ?>
<?php echo $item->get_date('j F Y # g:i a'); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php get_footer(); ?>
I see the image url in my rss feed now ( thanks to that functions script) and it is in a tag.
Looks like this: https://www.mywebsite./url-of-the-image/
They dont have a .jpg or .png extension at the end of the url. Not sure if that is how it needs to be. When I open that link I can see the image, and it works.
Can somebody please help me to figure this out ? I'm working on this thing for 2 days and can't figure it out. My PHP isn't great so that is most likely the reason why I can't figure it out.
Thanks in advance :)
I think you want your function to get the attachment src instead of the link, and echo that src into a <url> tag inside the <image> RSS element (see here).
Try this:
function add_my_rss_node() {
global $post;
if(has_post_thumbnail($post->ID)):
$thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID));
echo("<image><url>{$thumbnail}</url></image>");
endif;
}

Stop WordPress fetch_feed from stripping anchor tags

I am using the WordPress fetch_feed function to pull in some Tweets. All works nicely but all html tags are stripped from the content. I would like to stop anchor tags from being stripped but just can't quite nail it.
<?php
include_once(ABSPATH . WPINC . '/feed.php');
$rss = fetch_feed('https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=Your_LEAP_Lewes&rpp=3');
if( ! is_wp_error( $rss ) ) {
//max items is actually set in the twitter url un this case.
$maxitems = $rss->get_item_quantity(3);
$rss_items = $rss->get_items(0, $maxitems);
}
?>
<div class="twitter-feed">
<div class="twitter-header clearfix">
<h2>Our latest Tweets</h2>
Follow #Your_LEAP_Lewes
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
</div>
<ul class="twitter-ul clearfix">
<?php if ($maxitems == 0) echo '<li>No items.</li>';
else
// Loop through each feed item and display each item as a hyperlink.
foreach ( $rss_items as $item ) : ?>
<?php
//print_r($item);
?>
<li>
<?php echo $item->get_description(); ?>
<span class="tweet-date"><?php echo $item->get_date('j M'); ?></span>
</li>
<?php endforeach; ?>
</ul>
</div>
For one thing, I think your syntax may be wrong in your if/else code, plus it's really hard to read.
<?php
if ($maxitems == 0) {
echo '<li>No items.</li>';
} else {
// Loop through each feed item and display each item as a hyperlink.
foreach ( $rss_items as $item )
{
echo '
<li>'.$item->get_description().'
<span class="tweet-date">'.$item->get_date('j M').'</span>
</li>';
}
}
?>
I think because your else statement wasn't bracketed properly that it only executed the next line, which is a comment. I might be wrong, but this is still easier to read.
As far as stripping HTML tags, check out the strip_htmltags() function. If the WordPress implementation sets this, you may be able to override it in your code.

Wordpress Comment reply link does not appear

I am using custom code to print the comments but the problem is whatever i do, i cant print the comment reply link under any comment....
here is the code
<?php // Do not delete these lines
if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
die ('Please do not load this page directly. Thanks!');
if (!empty($post->post_password)) { // if there's a password
if ($_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password) { // and it doesn't match the cookie
?>
<p class="nocomments">This post is password protected. Enter the password to view comments.</p>
<?php
return;
}
}
/* This variable is for alternating comment background */
/*$oddcomment = 'class="alt" ';*/
$oddcomment = 'alt';
?>
<!-- You can start editing here. -->
<?php if ($comments) : ?>
<h3 id="comments"><?php comments_number('No Responses', 'One Response', '% Responses' );?> to “<?php the_title(); ?>”</h3>
<ol class="commentlist">
<?php foreach ($comments as $comment) : ?>
<!--<li <?php echo $oddcomment; ?>id="comment-<?php comment_ID() ?>">-->
<li class="<?php echo $oddcomment; ?> <?php if ($comment->comment_author_email == get_the_author_email()) { echo 'author_comment'; } ?>" id="comment-<?php comment_ID() ?>">
<?php echo get_avatar( $comment, 32 ); ?>
<cite><?php comment_author_link() ?></cite> Says:
<?php if ($comment->comment_approved == '0') : ?>
<em>Your comment is awaiting moderation.</em>
<?php endif; ?>
<br />
<small class="commentmetadata"><?php comment_date('F jS, Y') ?> at <?php comment_time() ?> <?php edit_comment_link('edit',' ',''); ?>
</small>
<?php comment_text() ?>
<div class="reply">
<?php comment_reply_link( array ( 'reply_text' => 'Reply this comment' ) );
?>
</div>
</li>
<?php
/* Changes every other comment to a different class */
/*$oddcomment = ( empty( $oddcomment ) ) ? 'class="alt" ' : '';*/
$oddcomment = ( empty( $oddcomment ) ) ? 'alt' : '';
?>
<?php endforeach; /* end for each comment */ ?>
</ol>
<?php else : // this is displayed if there are no comments so far ?>
<?php if ('open' == $post->comment_status) : ?>
<!-- If comments are open, but there are no comments. -->
<?php else : // comments are closed ?>
<!-- If comments are closed. -->
<p class="nocomments">Comments are closed.</p>
<?php endif; ?>
<?php endif; ?>
But when i use wp_list_comments functions i can see the reply link appear automatically i am using wordpress 3.2.1
It can be helpful to read the source for comment_reply_link (http://core.trac.wordpress.org/browser/tags/3.2.1/wp-includes/comment-template.php#L1061), as there are multiple conditions that can lead to the link not appearing. Work through each one at a time, and you'll likely find your answer.
The one that tripped me up, is that the link will not appear if comments are closed. So it can be helpful to review the comment settings on the blog to make sure that providing replies is actually allowed on this post.
Try this:
comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth'])))
Thanks to the following codex-entry (http://codex.wordpress.org/Function_Reference/comment_reply_link), I managed to find the actual use of the comment_reply_link() on the following link: http://core.trac.wordpress.org/browser/tags/3.2.1/wp-includes/comment-template.php#L1061
This leaves me with the following question - did you try adding either the second or the third parameter for the function? I think there might be something fishy going on under the hood, making the comment-link not know where to actually link.
Try removing the following snippet
comment_reply_link( array ( 'reply_text' => 'Reply this comment' ) );
and instead use the following one
comment_reply_link( array('reply_text' => 'Reply this comment'), comment_ID(), the_ID() );
Let me know if it works out for you!
Enable nested comments in Admin > Settings > Discussion:
Enable threaded (nested) comments levels deep

Resources