Create a post from every image in my media gallery

If you have the image in your media library you can just loop trough them and create post via wp_insert_post. function import_post_from_imgs() { $images = get_posts(‘post_type=attachment&post_status=inherit&posts_per_page=-1’); // just a minimal security check if ( ! current_user_can(‘publish_posts’) ) return; if ( ! empty($images) ) { foreach ( $images as $image) { // prevent duplicate if for … Read more

Adding Alt Tag Column to Media Library List

Here’s the code – function wpse_media_extra_column( $cols ) { $cols[“alt”] = “ALT”; return $cols; } function wpse_media_extra_column_value( $column_name, $id ) { if( $column_name == ‘alt’ ) echo get_post_meta( $id, ‘_wp_attachment_image_alt’, true); } add_filter( ‘manage_media_columns’, ‘wpse_media_extra_column’ ); add_action( ‘manage_media_custom_column’, ‘wpse_media_extra_column_value’, 10, 2 ); It could go to functions.php file or into your plugin.

zip unzip attachments in wordpress

WordPress provides a function called unzip_file()— easily found by typing “wordpress unzip” into Google. There is sample code in the Codex: WP_Filesystem(); $destination = wp_upload_dir(); $destination_path = $destination[‘path’]; $unzipfile = unzip_file( $destination_path.’/filename.zip’, $destination_path); if ( $unzipfile ) { echo ‘Successfully unzipped the file!’; } else { echo ‘There was an error unzipping the file.’; } … Read more

Dynamically Insert Image Into Stylesheet

Typically with themes that support custom styles/images, you define everything you can in your stylesheet, and then add the dynamic styles inline: .header { background-position: 50% 50%; background-repeat: no-repeat: background-size: whatever; } And in your templates: <div class=”header”<?php if ( $image ) printf( ‘ style=”background-image: url(%s);”‘, $image ) ?>> Title </div>

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