WP SEO by Yoast - How to change og:image size? - php

I want to change the og:image that Yoast SEO generates, to some custom height and width (eg 1200x630) because I'm uploading very large images. I've tried adding this code in functions.php but doesn't work. Please help
function add_share_image_sizes() {
add_image_size( 'facebook-share', 1200, 630, true );
}
add_action( 'after_setup_theme', 'add_share_image_sizes' );
function set_yoast_facebook_share_image_size() {
return 'facebook-share';
}
add_filter( 'wpseo_opengraph_image_size', 'set_yoast_facebook_share_image_size' );

You need to pass a parameter.
function add_share_image_sizes() {
add_image_size( 'facebook-share', 1200, 630, true );
}
add_action( 'after_setup_theme', 'add_share_image_sizes' );
function set_yoast_facebook_share_image_size($img_size) {
return 'facebook-share';
}
add_filter( 'wpseo_opengraph_image_size', 'set_yoast_facebook_share_image_size' );

Related

Can't remove WooCommerce's image zoom

I am trying to remove the image zoom from my custom themed website which uses WooCommerce. Here is what I've tried adding in my functions.php file:
add_action( 'after_setup_theme', 'remove_pgz_theme_support', 100 );
function remove_pgz_theme_support() {
remove_theme_support( 'wc-product-gallery-zoom' );
}
and this
add_action( 'wp', 'remove_pgz_theme_support', 20 );
function remove_pgz_theme_support() {
remove_theme_support( 'wc-product-gallery-zoom' );
}
I've spend some time googling but the answers always recommend trying something along the lines of the above.
I disable all image effects with:
add_action('wp', 'remove_woo_image_effects');
function remove_woo_image_effects() {
// this should be disable the gallery slider and lightbox
remove_theme_support('wc-product-gallery-lightbox');
remove_theme_support('wc-product-gallery-slider');
// this should be disable the zoom
remove_theme_support('wc-product-gallery-zoom');
}
I tested it with DIVI and two from my custom themes
checked it here with custom theme
The solution that worked for me is adding the following to your functions.php file
// Add WooCommerce support
function add_woocommerce_support() {
add_theme_support( 'woocommerce' );
}
add_action( 'after_setup_theme', 'add_woocommerce_support' );

Add Image Size in Wordpress not working

I'm trying to add images sizes on my wordpress site. I searched alot and tried too many solutions but couldn't work for me can anyone help me on this, it will be appreciatable. Thanks in advance. I have added this code in my functions.php file
add_filter( 'image_size_names_choose', 'my_custom_sizes' );
function my_custom_sizes( $sizes ) {
return array_merge( $sizes, array(
'slider_image_desktop' => __( 'slider_image_desktop' ),
) );
}
add_action( 'after_setup_theme', 'wpse_setup_theme' );
function wpse_setup_theme() {
add_theme_support( 'post-thumbnails' );
add_image_size( 'slider_image_desktop2', 60, 60, true );
}
Thanks everyone i solved my problem. I changed my some lines of code to
add_action( 'after_setup_theme', 'wpse_setup_theme' );
function wpse_setup_theme() {
add_theme_support( 'post-thumbnails' );
if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'slider_image_desktop2', 60, 60, true );
}
}
It made the thumbnail then for retrieving i didn't use function for get image thumb because i am using Advanced Custom Fields so in wp admin in my acf fields group i just checked my image uploader's return value as image array and i just got full array of the uploaded image with my defined size. there was no need to use wp_get_attachment_image_src or wp_get_attachment_image function to fetch the image..
Thanks everyone for your help may this answer will help someone who will have been the same problem...
Try This:
$attachment_id = get_field('field_name');
$size = "slider_image_desktop2"; // (thumbnail, medium, large, full or custom size)
$image = wp_get_attachment_image_src( $attachment_id, $size );
// url = $image[0];
// width = $image[1];
// height = $image[2];
?>
<img class="image-class" alt="" src="<?php echo $image[0]; ?>" />
<?php
just copy and paste on your theme function.php file
add_image_size( 'img-cropped', 198, 198, true );// you can change the size
Your selected self answer was an absolute life saver, and got me to the point of what I was trying to do - but I had to make one small addition to get the custom image size in the backend page editor "add media" options:
function nmg_custom_sizes( $sizes ) {
return array_merge( $sizes, array(
'social-icons' => __('Social Icon'),
) );
}
add_action( 'after_setup_theme', 'nmg_setup_theme' );
function nmg_setup_theme() {
add_theme_support( 'post-thumbnails' );
if ( function_exists( 'add_image_size' ) ) {
add_image_size('social-icons', 9999, 60, false);
}
add_filter( 'image_size_names_choose', 'nmg_custom_sizes' );
}
It's your function, but with the function to add the custom size to image_size_names_choose - but after theme setup (what was stopping it from working for me before).
Might be useful to someone...

how can i stop these 2 wordpress functions from interfering with each other?

i have a specific word press theme and a plugin for counting downloads.... however when i activate the plugin it makes all my "featured thumbnails" disappear for all the post types in my wordpress... in other words there is no "featured image box" when adding any kind of post AFTER i activate the plugin......
after looking through my theme code and the plugin code i believe i have found the problem but i am not sure hoe to fix it.....
the theme i am using has the following function
// Add Thumbnail support
if (function_exists('add_theme_support')) { // Adding thumbnail support to all post types.
add_theme_support( 'post-thumbnails', array( 'store', 'dlm_download', 'service', 'album', 'mixtape', 'merch', 'photos', 'video' , 'download' , 'homebanner', 'post' ) );
add_image_size('storeimage', 200, 200, true); //Store homepage Thumbnails
add_image_size('beat_page', 160, 160, true); // Single beat page
add_image_size('photo', 200, 200, true); // Thumbnail image
add_image_size('photowidget', 165, 165, true); // Thumbnail image
add_image_size('videowidget', 270, 151, true); // Thumbnail image
add_image_size('photobig', 570, 570, true); // Image for single page
add_image_size('videoimage', 273, 200, true); // Video Gallery Homepage Thumbnails
add_image_size('homebannerimage', 920, 350, true); //Homepage Banner Image
add_image_size('featuredimage', 580, 250, true); //Post Featured image Image 580x250
}
and then the plugin has the following function
public function compatibility() {
// Post thumbnail support
if ( ! current_theme_supports( 'post-thumbnails' ) ) {
add_theme_support( 'post-thumbnails' );
remove_post_type_support( 'post', 'thumbnail' );
remove_post_type_support( 'page', 'thumbnail' );
} else {
// Get current supported
$current_support = get_theme_support( 'post-thumbnails' );
// This can be a bool or array. If array we merge our post type in, if bool ignore because it's like a global theme setting.
if ( is_array( $current_support ) ) {
add_theme_support( 'post-thumbnails', array_merge( $current_support, array( 'dlm_download' ) ) );
}
add_post_type_support( 'download', 'thumbnail' );
}
}
i noticed they both use "add_theme_support" , "post-thumbnails" and a few other similar things...... not sure why the two functions are interfering with each other or how i could fix it...... i tried to add the "dlm_download" post type (this is the post type for the the plugin) to the theme functions array of post types and it didnt make any difference.....
i tried to totally remove the thumbnail function from the plugin and kept getting a "failed to call header : head already called" error....
any help would be much appreciated!
Try changing this line in your theme
add_theme_support( 'post-thumbnails', array( 'store', 'dlm_download', 'service', 'album', 'mixtape', 'merch', 'photos', 'video' , 'download' , 'homebanner', 'post' ) );
to
add_theme_support( 'post-thumbnails' );

Remove/update add_image_size in Wordpress Parent theme functions.php file

I'm creating a child theme from a parent theme in Wordpress. I would like to change the defined image sizes in the parent's functions.php file:
/* Image sizes */
add_action( 'init', 'oxygen_image_sizes' );
/**Image sizes**/
function oxygen_image_sizes() {
add_image_size( 'archive-thumbnail', 470, 140, true );
add_image_size( 'single-thumbnail', 470, 260, true );
add_image_size( 'featured-thumbnail', 750, 380, true );
add_image_size( 'slider-nav-thumbnail', 110, 70, true );
}
Here is a link that I found that seems pretty straightforward but it's not working for me.
https://wordpress.stackexchange.com/questions/74934/remove-or-update-add-image-size
Here is the code that I'm using in my child theme's functions.php file:
function child_theme_setup() {
add_image_size( 'archive-thumbnail', 600, 140, true );
add_image_size( 'single-thumbnail', 600, 260, true );
add_image_size( 'featured-thumbnail', 600, 380, true );
}
add_action( 'after_setup_theme', 'child_theme_setup', 11 );
Many thanks!
The Hook after_setup_theme is called before init.
So your settings get overwritten by the settings from the parent theme.
You can also use init to hook into and with the higher priority (11) your setting will be used.
OR
You remove the oxygen_image_sizes-action and re add all the image-sizes with your own function.

How do I add Typekit Script to Wordpress?

Is it possible to add the the typekit embed code to wordpress by using wp_enqueue_script()?
Here is what I have so far but I'm not seeing any results:
function typekit_enqueue_script() {
wp_enqueue_script(
'typekit',
'//use.typekit.net/weq7wou.js',
array(),
null,
true
);
}
add_action( 'wp_enqueue_script', 'typekit_enqueue_script' );
Are you loading Typekit afterwards?
function load_typekit() {
echo '<script>try{Typekit.load();}catch(e){}</script>';
}
add_action( 'wp_head', 'load_typekit', 300 );
Or just add the load script in one of your js:
try{Typekit.load();}catch(e){}
This should work:
wp_enqueue_script( 'typekit','//use.typekit.net/weq7wou.js',array() );

Categories