Redirect Attachment Page to Attachment

You can’t redirect after content has already been sent to the browser, hook an action before the template is loaded and do your redirect there. function wpa_attachment_redirect(){ if( is_attachment() ){ // your code and redirect here } } add_action( ‘template_redirect’, ‘wpa_attachment_redirect’ );

Media/attachment urls don’t redirect with fake URL structure

Milo got me on the right track. If anyone else happens to have this issue the code I used is: /** * Redirect broken attachment links to 404 */ function ww_404_broken_links(){ global $wp_query; if(is_attachment()){ $attachment_path = get_attached_file( get_the_ID() ); //If the file doesn’t exist on the server show 404 if(!file_exists($attachment_path)){ $wp_query->set_404(); status_header( 404 ); get_template_part( … Read more

Weird string offset errors when displaying post attachments

Since you’ve used the true argument for get_post_meta, $blogimages will be a single array, not a multidimensional one. So instead of $blogimages[0][‘blog-image-inside’], just use $blogimages[‘blog-image-inside’]. For absolute sanity, you might also want to check $blogimages before you use it: ‘exclude’ => [ $thumb_ID, isset( $blogimages[‘blog-image-inside’] ) ? $blogimages[‘blog-image-inside’] : 0, isset( $blogimages[‘blog-image-front’] ) ? $blogimages[‘blog-image-front’] … Read more

How do you import images from a URL in your post?

You could create a small plugin for this, here is an small example that will try to download and attach a file based on the url in the excerpt field for the post: add_action(‘publish_post’, ‘auto_featured_image_publish_post’); function auto_featured_image_publish_post($post, $post_id) { // check if this post is saved for the first time if($post->post_date == $post->post_modified) { // … Read more

Call to undefined function wp_generate_attachment_metadata()

Despite you already solved it (the “undefined” issue), it should be noted that wp_generate_attachment_metadata() is defined in wp-admin/includes/image.php, so you need to manually load that file if you’re using the function on the front-end, i.e. public side of the site or non admin/wp-admin pages (e.g. single attachment pages). And in fact, the function reference says … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)