Add real="pretyphoto" to wordpress gallery image - gallery

I m already using Pretyphoto script in my theme to open the featured images in a nice lightbox.
And now I would like to add rel="pretyphoto" to the wordpress gallery image
I can't do it manually because I will need to edit the media.php core file
So I would like to use a function that will do the job.
I already found solution for comments here :
function add_nofollow_to_comments_popup_link() {
return ' rel="nofollow" ';
}
add_filter( 'comments_popup_link_attributes', 'add_nofollow_to_comments_popup_link' );
So I would need something similar for the gallery image of wordpress.
Thanks

Found answer myself :
Here is the Solution for anyone who is interested.
Add this code in your theme functions.php
add_filter( 'wp_get_attachment_link', 'sant_prettyadd');
function sant_prettyadd ($content) {
$content = preg_replace("/<a/","<a rel=\"prettyPhoto[slides]\"",$content,1);
return $content;
}
And the gallery attachement must be MEDIA FILE

Related

Custom product page layout by category ( Woocommerce )

I'm new to php and Woocommerce. I know this question has already been asked but i can't figure out how to make it work ... Right now, i have 3 different categories on my Woocommerce shop ( i'm developping using Understrap ). I've created my basic product page layout, everything works fine. Now, i'd like to create a custom layout for my products that are in my "cleaning" category.
What i did for now is add this to my functions.php child theme :
add_filter('template_include', 'cleaning_single_product_template_include', 10);
function cleaning_single_product_template_include($template)
{
if (is_product() && (has_term('cleaning', 'product_cat'))) {
$template = get_stylesheet_directory() . '/woocommerce/single-product-cleaning.php';
}
return $template;
}
Then i've created a single-product-cleaning.php file inside my woocommerce folder. For now, i've just pasted an <h1>LOREM</h1> to see if it shows up on the page, but it doesn't ..
Now in the code i've added to my functions.php, if i replace the content of my function with a simple
echo "test"; die();
It works, the "test" message appears on my cleaning product pages. But if i let the code i've written as is, then it just display the regular product page from single-product ... Any idea what i am missing here ?
EDIT : i've found this thread on stackoverflow where he seems to have found a solution (see his last comment) but i don't understand what code he moved or how he solved it ..
Finally fixed! For those having the same problem, i've just modified a little bit my functions.php function like this :
add_filter('template_include', 'cleaning_single_product_template_include', 50, 1);
function cleaning_single_product_template_include($template)
{
if (is_singular('product') && (has_term('cleaning', 'product_cat'))) {
$template = get_stylesheet_directory() . '/woocommerce/single-product-cleaning.php';
}
return $template;
}

Wordpress shortcodes not working on posts but wornikg on pages

When I use shortcode on page works good but on posts is displayed only shortcode name.
Example shortcode:
function foobar_func( $atts ){
return "foo and bar";
}
add_shortcode( 'foobar', 'foobar_func' );
Usage:
[foobar]
On page is displayed
foo and bar
but on post only
[foobar]
I tryied on basic theme like TwentySeventenn and the problem still exists.
It's very strange. So you added the above code to TwentySeventenn theme's functions.php, but it does not work on post? Please double check you write [foobar] correctly on your post content file.
Or if you changed something on the theme, please check you used the_content() instead of echo get_the_content();
shortcodes are not working if you use get_the_content();

how to use a wp plugin as a theme part not as a plugin?

I am developing a word press theme and I have a free plugin which helps me to add new features to my theme. I want to use this plugin in this theme but I don't want to use it as a plugin and have to activate in plugins section. I want to use it as a theme part and disable activating or deactivating it. It will be activate automatically when theme set up.
If your theme uploaded somewhere then refer -> https://wordimpress.com/how-to-easily-require-plugins-for-your-wordpress-themes/
Or
add_action( 'admin_notices', 'my_theme_dependencies' );
function my_theme_dependencies() {
if( ! function_exists('plugin_function') )
echo '<div class="error"><p>' . __( 'Warning: The theme needs Plugin X to function', 'my-theme' ) . '</p></div>';
}
OR
if your theme is in local setup then you can use must-up plugin, for that refer -> https://codex.wordpress.org/Must_Use_Plugins
So if I understand correctly you want your plugin to be in Wordpress but you don't want it to be shown to anyone else or be able to deactivate it?
Try using this plugin, which will hide your plugin('s) from everyone - WP Hide Plugins.
Or add this to your functions.php file:
function hide_plugin_trickspanda() {
global $wp_list_table;
$hidearr = array('plugin-directory/plugin-file.php');
$myplugins = $wp_list_table->items;
foreach ($myplugins as $key => $val) {
if (in_array($key,$hidearr)) {
unset($wp_list_table->items[$key]);
}
}
}
add_action('pre_current_active_plugins', 'hide_plugin_trickspanda');
Info to go with this code: rename the plugin name in the first line, also change the "plugin-directory/plugin-file.php" to the plugin file of your plugin and in the last line change the plugin name too.

Set default image for woocommerce products

In my project I have many products whose image is not available till now. So I want to show custom image for those products who don't have image.
Is there a way to set default image for products (in case if product don't have image).
I solved it by adding following code in functions.php file
add_action( 'init', 'custom_fix_thumbnail' );
function custom_fix_thumbnail() {
add_filter('woocommerce_placeholder_img_src', 'custom_woocommerce_placeholder_img_src');
function custom_woocommerce_placeholder_img_src( $src ) {
$upload_dir = wp_upload_dir();
$uploads = untrailingslashit( $upload_dir['baseurl'] );
$src = $uploads . '/2012/07/thumb1.jpg';
return $src;
}
}
NOTE : Do not type complete url of image. Instead of complete url, use only short url as shown in code.
Original Post
TLDR;
You need to upload an image via default Wordpress Media uploader, then copy its URL (or just ID) and paste it to "WooCommerce->Settings->Products->Placeholder image"
Found an answer here: https://www.iqcomputing.com/support/articles/changing-the-woocommerce-default-image/

Genesis child theme - Remove primary sidebar on homepage only

I have been looking all over the place and am unable to find a solution. I am using Genesis Child theme "news" and for the homepage I don't need the primary sidebar, because I'll have an image slider there instead. I have found code such as this:
/** Force full width layout */
add_filter( 'genesis_pre_get_option_site_layout', 'child_do_layout' );
function child_do_layout( $opt ) {
$opt = 'full-width-content'; // You can change this to any Genesis layout below
return $opt;
}
and added it to the functions page, because I want to essentially force a full width page for home.php, however it hasn't worked.
If anyone has had success with this, any help is appreciated.
nevermind, I found the solution to anyone who is curious, to the home.php file add:
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );

Resources