Wordpress images link - wordpress

I'm just starting with wordpress. I create blog and right now I have index.php with list of posts. If I add images to posts in admin panel , images have href but they redirect to attachment - not to post. Of course I can use:
has_post_thumbnail()
but this works only if I set it in admin.
My question is : How to create redirect to post as default (not to attachment ) for images added to post.

This is typical of WordPress and is supposed to happen. It is up to the author when inserting media into the page how it is displayed. See the Attachment Settings in the Bottom Right of the Corner. You will want to select None or Custom URL based on your preferences. Yours is currently set to "Media File" Like the screenshot below.
You can add this snippet of code to your themes functions.php file to change the default settings:
function image_overrides() {
update_option('image_default_align', 'center' ); // Changes the alignment
update_option('image_default_link_type', 'none' ); // Changes the Link type
update_option('image_default_size', 'large' ); // Changes the default size
}
add_action('after_setup_theme', 'images_overrides');

Related

How to force WordPress Gutenberg to update the featured image after saving the post?

I am working on a plugin that automatically attaches a featured image to a WordPress post after save (i.e. programmatically not using the Media Selector). The plugin uses the add_action( 'save_post_post', 'myFunction'); hook to save the image to the post.
The Gutenberg UI does not update the featured image thumbnail in the metabox on the right column.
I have tested and verified that the image is successfully updated and attached to the post, and does show if you manually reload the page.
From what I can tell, I need to tell Gutenberg the featured image has been changed in order for it to be updated in the view.
I have been unable to locate a hook or action I can use to trigger such a refresh after the user presses the "Save" button.
What is the appropriate way accomplish this refresh (from within my plugin PHP file)?
The way I see it, WordPress takes care of the update for you. Maybe you didn't use the right hook?
When I use the following, my posts have a default thumbnail, whenever I open a new plugin page:
function custom_add_thumbnail( $post_ID ) {
set_post_thumbnail($post_ID, 67);
return $post_ID;
}
add_action( 'save_post', 'custom_add_thumbnail' );
If this doesn't help, please share your code, maybe in pastebin, so I can investigate further.

How to return output of the new WordPress 5+ gallery block for automatically link images to media file?

I mange a multi-writers blog, and all our users uploading some gallery images, and they didn't know the difference between (attachment, media file or none). I found solution to hide the link panel, but I am editing all the published posts to change the gallery images link to file "manually".
Before WordPress version 5 I was linked all gallery images to "file" automatically by using this filter below.
add_filter( 'shortcode_atts_gallery',
function( $out ){
$out['link'] = 'file';
return $out;
}
);
But after WP 5+ how can I make it to work again? I really need to link all gallery images to "media file" automatically!

How to rewrite custom title and description only for blog in WordPress using child theme functions.php

How can I rewrite meta title and description in Wordpress using child theme functions.php?
I want to rewrite it only on main blog page (for example: www.example.com/blog), where I have listed all articles.
The problem is that the main theme already adds title and description to blog page. So I need to remove them first and then add custom ones.
Thank you very much for your help.
First off, WordPress does not add a <meta name=decription> tag. That is usually done by a seo plugin like Yoast, therefor the method for overriding it differ per plugin. Or theme.
You might be a able to change these texts in the wp-admin settings, again depending on the plugin/theme.
The title you should be able to change using this example:
function SO_52811727_wp_title($title) {
// see https://codex.wordpress.org/Conditional_Tags for more options
if ( is_archive() ){
$title = 'custom title';
}
return $title;
}
add_filter('wp_title', 'SO_52811727_wp_title', 100);

Custom headers for each pages in wordpress

I am using Meteor Slides plugin for showing header in slideshow.Now what i need is to show this header on only home page and show different header images in different pages. I got a plugin called "WP Display header" for displaying different header images for different pages.But the slideshow header along with two custom headers with same image which i set using WP Display Header plugin. How can solve this problem and show the slideshow on the homepage only and different headers in different pages? Someone please help me.
I have got answer for it. I have changed the code to add meteor slides plugin in functions.php to show the slideshow just in the homepage.
<?php if ( is_front_page() ) {
if ( function_exists( 'meteor_slideshow' ) ) {
meteor_slideshow();
}
} ?>
After that i used a plug called WP display header to set header image for each page

How to change default post attributes?

My site needs to have image based posts, meaning the post is only an image.
Now i tried implementing it with Custom Post Types, but have encoutred problems,
like categories didn't show the right posts, pagination caused problems etc.
Now i thought to myself that i don't need the regular posts and if i could just edit them
to have only the featured image option enabled, life would be much easier.
But i failed to find any information regarding this.
Anyone can help me please?
To add featured image support/option simply add the following code snippet to your functions.php file located inside your theme's root folder
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
}
and to show the featured image inside your template you can do
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail(); // will show the featured image if you have set any for the post
}
Applicable to Wordpress version-2.9 and higher.
When you add new post just find the featured image meta box and set an featured image from there.
You can also setup image sizes (depending on that images will be displayed) at the front end, just take a look at here.

Resources