how to get wp plugin url with echo in variable? - wordpress

I'm working on a plugins in wordpress. I want to push some data in my database
I d like to get someting like this for my logos:
$logoname = "<img src='".$pluginlocation."".$name.".gif'>";
with something like that (that, which does not work) :
$pluginlocation = echo plugin_dir_url( __FILE__ ) .'/image' ;
tx ;)

Try below code :
<?php
echo '<img src="' . plugins_url( 'images/your_image_name.gif', dirname(__FILE__) ) . '" > ';
?>
for more detail on this please refer https://codex.wordpress.org/Function_Reference/plugins_url

Related

WP/WooComm Adding a variable to a complicated shortcode

I have a shortcode where I need to dynamically insert the current WordPress/ WooCommerce category to it.
The raw shortcode is
[content_control]
[product_table category="product-cateegory-name" columns="sku,name,cf:size,cf:pgk_qty,cf:case_qty,cf:case_wt,stock,price,buy,cf:dia_pitch,cf:length,cf:inner_box_q,cf:inner_box_length,cf:inner_box_width,cf:inner_box_height,cf:outer_box_qty,cf:outer_box_length,cf:outer_box_width,cf:outer_box_height,cf:outer_box_weight" column_breakpoints="all,all,all,all,all,all,all,all,all,none,none,none,none,none,none,none,none,none,none,none,none"]
[/content_control]
I was trying
<?php echo do_shortcode("[content_control]"); ?>
<php
$cate = get_queried_object();
$cateID = $cate->term_slug;
?>
<?php echo do_shortcode("[product_table category="'. $cateID .'" columns="sku,name,cf:size,cf:pgk_qty,cf:case_qty,cf:case_wt,stock,price,buy,cf:dia_pitch,cf:length,cf:inner_box_q,cf:inner_box_length,cf:inner_box_width,cf:inner_box_height,cf:outer_box_qty,cf:outer_box_length,cf:outer_box_width,cf:outer_box_height,cf:outer_box_weight" column_breakpoints="all,all,all,all,all,all,all,all,all,none,none,none,none,none,none,none,none,none,none,none,none"]"); ?>
<?php echo do_shortcode("[/content_control]"); ?>
But I think inserting the variable this way won't work.
I think there is something basic I'm missing
This worked. I had to escape the "s within the PHP and connect the two arguments in the shortcode via a ' . '
$cate = get_queried_object()->slug;
echo do_shortcode("[product_table category=\"' . $cate . ' \" columns=\"sku,name,cf:size,cf:pgk_qty,cf:case_qty,cf:case_wt,stock,price,buy,cf:dia_pitch,cf:length,cf:inner_box_q,cf:inner_box_length,cf:inner_box_width,cf:inner_box_height,cf:outer_box_qty,cf:outer_box_length,cf:outer_box_width,cf:outer_box_height,cf:outer_box_weight\"' . 'column_breakpoints=\"all,all,all,all,all,all,all,all,all,none,none,none,none,none,none,none,none,none,none,none,none\"']"); ?>```

qtranslate-X woocommerce grouped Products

I searched the internet for a possible solution but wasnt able to find one.
The Labels of linked products in a grouped product apear like:
[:de]german value[:en]english value[:]
My goal is to get the title/label in the current languge of my site
do I need to edit the call of my label in grouped.php?
if you need any further information tell me.
You have to edit grouped.php inside /wp-content/themes/YOUR_THEME/woocommerce/single-product/add-to-cart/grouped.php
Wrap all the instances of $grouped_product->get_name() into a __() function.
In my case I had the following code in grouped.php:
<?php echo $grouped_product->is_visible() ? '<a href="' . esc_url( apply_filters( 'woocommerce_grouped_product_list_link', get_permalink( $grouped_product->get_id() ), $grouped_product->get_id() ) ) . '">'
. $grouped_product->get_name() . '</a>' : $grouped_product->get_name(); ?>
so I used the translation function __() to get rid of qTranslate-X language tags:
<?php echo $grouped_product->is_visible() ? '<a href="' . esc_url( apply_filters( 'woocommerce_grouped_product_list_link', get_permalink( $grouped_product->get_id() ), $grouped_product->get_id() ) ) . '">'
. __($grouped_product->get_name()) . '</a>' : __($grouped_product->get_name()); ?>

Wordpress post tags are not working

I ma fetching post and tags manually and forming tags url properly but still tags link not working. On click In Browser inspect network tab sending ajax request to admin-ajax.php automatically.
if (is_array(get_the_tags($post->ID)) || is_object(get_the_tags($post->ID))) :
foreach(get_the_tags($post->ID) as $tag)
{
echo '<li>' . $tag->name . '</li> ';
}
endif;
Links to verify; http://139.162.60.231/fow/
Html Formed :
Startup
Try using this:
$post_id = get_the_ID();
if (is_array(get_the_tags($post_id)) || is_object(get_the_tags($post_id))) :
foreach(get_the_tags($post_id) as $tag)
{
echo '<li>' . $tag->name . '</li> ';
}
endif;

How to show image url in wordpress foreeach loop?

I need to display sub categories from a particular category
<?php
$subcategories = get_categories('&child_of=22&hide_empty');
foreach ($subcategories as $subcategory) {
echo '<a href="' . get_category_link( $subcategory->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $subcategory->name ) . '" ' . '>' . $subcategory->name.'</a>';
echo '<p>'.$subcategory->description.'</p>';
}
?>
I tried this
echo '<img class='hline' src='bloginfo('template_url')/img/hline.png' alt=''>';
its not working
You need to look at the basics of strings and concatenation in PHP.
You open your string with single quotes so you can't then use single quotes for HTML attributes unless you escape them first (\'hline\'). Instead you should be using double quotes for those attributes.
Then you need to break out of your string in order to use your PHP function, bloginfo(). With that said it makes more sense to use get_template_directory_uri() instead (or stylesheet directory depending on your setup).
Complete example:
echo '<img class="hline" src="' . get_template_directory_uri() . '/img/hline.png" alt="" />';
Documentation: http://php.net/manual/en/language.types.string.php
I would use instead:
get_template_directory_uri()
And I like to write it like this but that depends internally on you.
<img class="hline" src="<?php echo get_template_directory_uri();?>/img/hline.png" alt="" />';

how to require file from plugin directory of wordpress in theme page

I want to require_once an html file from plugin directory of wordpress in the custom page of wordpress
i have tried
require_once(WP_PLUGIN_URL."/sinetiks-schools/images/t1.php");
but getting an error
require_once(): http:// wrapper is disabled in the server configuration by allow_url_include=0 i
Try this:
<?php
echo '<img src="' . plugins_url( 'images/wordpress.png', dirname(__FILE__) ) . '" > ';
$dir = plugin_dir_path( __FILE__ );
var_dump($dir);
?>

Resources