I am working on a website on WordPress and I’m getting an undefined variable in image url. WordPress automatically links to a random previous post with a picture from that previous link if there is a previous post but this notice keeps popping up on the bottom of my latest post. This does not show up on any other post. It says there is something wrong with the previous post image url. Since it is undefined should I try to define it in the code and include a url and image url from one of my previous posts to see if that works? This is where it says the error is on. And if I do define it myself, what is the code that I should input to create a variable for image url?
previous_post_link( '%link', '<div class="post-navigation-image"><img src="' . $previous_post_image_url . '" /></div><div class="post-navigation-content"><div class="post-navigation-title"><span class="next-post">Next Post ></span><h3>%title</h3></div></div>' );
echo '</div>';
You should add validation to check if the variable exists before trying to use it. If the variable does not exist, then you can assign a default value to that variable which will be used to avoid error.
$previous_post_image_url = !empty($previous_post_image_url) ? $previous_post_image_url : '';
previous_post_link( '%link', '<div class="post-navigation-image"><img src="' . $previous_post_image_url . '" /></div><div class="post-navigation-content"><div class="post-navigation-title"><span class="next-post">Next Post ></span><h3>%title</h3></div></div>' );
echo '</div>';
Related
I'm hoping someone can clue me in on how I can extract a plugin value and display it on my page using a short code. Specifically, when a user reaches the max allowable limit, I would like a notification message to appear on the page (in addition to its placement in a popup) Many tests and I have not been able to get this to work. MANY thanks in advance.
public function add_error_limit_message() {
if ( ! $this->limit_reached ) {
return;
}
$message = apply_filters( 'woocompare_limit_reached_message', __( 'You have reached the maximum number of products for compare table.', 'woocommerce-compare' ) );
echo '<div class="woocompare-error"><p>' . wp_kses_post( $message ) . '</p></div>';
}
add_shortcode( 'limit-reached-message', 'add_error_limit_message' );
Your shortcode function should return the text string you want to insert in place of the shortcode, not echo it.
To track down "critical errors" (php errors) turn on WP_DEBUG and WP_DEBUG_DISPLAY in your wp-config.php file. And try installing and activating the Query Monitor plugin. These will tell you enough about your php errors to track them down and fix them.
I'd like to add a tooltip like this in order status, on mouse over:
I tried to use wc_help_tip as follows:
$help_tip = 'Ti do un suggerimento: studia!';
echo wc_help_tip(__($help_tip, 'mypluginname'));
As a result I get a similar behaviour: I display a question mark icon and on mouse over my custom text. I'd like to display my text in the same style as in WooCommerce order status column. Any suggestions?
I solved by myself using data-tip property as follows:
echo '<mark style="margin-bottom:2px;" class="order-status status-on-hold tips" data-tip="' . __('Document not created in MyPluginName', 'mypluginname') . '"><span>'. __('Not saved ', 'mypluginname') . '</span></mark><br />';
There is a line of code that I cannot change within the WooCommerce Template files. This line of code is displayed at the top of the view order page within my account / orders / view order
This is the code displayed in the inspector;
<p>Order #<mark class="order-number">58</mark> was placed on <mark class="order-date">3rd July 2018</mark> and is currently <mark class="order-status">Cancelled</mark>.</p>
And the only code I can find which is similar is in the tracking.php template file;
<p class="order-info"><?php
/* translators: 1: order number 2: order date 3: order status */
echo wp_kses_post( apply_filters( 'woocommerce_order_tracking_status', sprintf(
__( 'Order #%1$s was placed on %2$s and is currently %3$s.', 'woocommerce' ),
'<mark class="order-number">' . $order->get_order_number() . '</mark>',
'<mark class="order-date">' . wc_format_datetime( $order->get_date_created() ) . '</mark>',
'<mark class="order-status">' . wc_get_order_status_name( $order->get_status() ) . '</mark>'
) ) );
?></p>
The problem is that this code has a class on the p tag the one in the inspector doesn't. And if I edit this code there are no changes on the front end. But the code looks the same so I'm not sure if this is the correct template file for this code?
Where can I find this code in the template files or is this the correct file and something is going wrong?
There is another instance here: wp-content\plugins\woocommerce\templates\myaccount\view-order.php on line 30. Is that the what you are looking for?
If you completely comment this section on the WooCommerce plugin file, does it still echos? if yes, it might coming from a template file override, or it's not that file.
If this is the code, you should be able to add filter with the highest priority to change the content.
I have a wordpress blogg where i want to change the value of the "more" tag. I tried to change "the content" code that is in the post but that wont work.
I have tried to look trough every file i can find without managing to change the value that is "read more..".
When i look in the sourcecode i can se this
"class="more-link">(mer…)</a></p>"
Anyone got any ide where i could change it ? right now i do not know what i should do.
try this one
function new_excerpt_more($more) {
global $post;
return '<a class="moretag" href="'. get_permalink($post->ID) . '"> Read the full article...</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');
Almost sure that I'm not the first one that has this question but when I test my (WordPress) page on Google Snippet Test Tool I got hatom-enty errors like:
hatom-feed
hatom-entry:
Fout: At least one field must be set for HatomEntry.
Fout: Missing required field "entry-title".
Fout: Missing required field "updated".
Fout: Missing required hCard "author".
I found some tutorials about this but that is for standard WordPress themes. I'm using Inovado from ThemeForest and I can't figure out in which file I have to edit this data.
Someone familiar with this?
I also got problems with snippet review... Good in testresults but doesn't show up in de Google Search Results. Don't know why...
You can Add this code to the function.php file in your theme's directory and it will solve the problems.
//mod content
function hatom_mod_post_content ($content) {
if ( in_the_loop() && !is_page() ) {
$content = '<span class="entry-content">'.$content.'</span>';
}
return $content;
}
add_filter( 'the_content', 'hatom_mod_post_content');
//add hatom data
function add_mod_hatom_data($content) {
$t = get_the_modified_time('F jS, Y');
$author = get_the_author();
$title = get_the_title();
if(is_single()) {
$content .= '<div class="hatom-extra"><span class="entry-title">'.$title.'</span> was last modified: <span class="updated"> '.$t.'</span> by <span class="author vcard"><span class="fn">'.$author.'</span></span></div>';
}
return $content;
}
add_filter('the_content', 'add_mod_hatom_data');
The code contains 2 functions. The first function will use the WordPress filter hook for “the_content” to add the class of “entry-content” to the article. To add in the other essential hAtom fields, the second function will add a short sentence to the end of your post article, which contains updated time, post title and author, with required microdata.