display post pdf attachments in side bar with link text
display post pdf attachments in side bar with link text
display post pdf attachments in side bar with link text
it was completely my bad. I am using this plugin and I updated my functions.php file but the plugin wasn’t activated although I thought it had been. Extension is here & it works in 5.4.2 with Gutenberg blocks if anybody is intereested: https://github.com/jchristopher/attachments
I found the problem. It was updating the post instead of the attachment. So instead of $post->ID, I create another string that stores the image ID and replace that with post->ID and it works. function post_extra_save( $post_id, $post){ if ( has_blocks( $post->post_content ) ) { $blocks = parse_blocks( $post->post_content ); foreach ( $blocks as $block … Read more
Custom image size not displaying with wp_get_attachment_image()
$mp3Link = wp_get_attachment_url($mp3_file_id); $mp3Link = str_replace( ‘example.com’, ‘sub.example.com’, $mp3Link ); <a class=”w3-black” href=”‘.$mp3Link.'” rel=”nofollow” >mp3</a> replace example.com with your actual domain – it’s not the most elegant solution, but might work.
There are three issues in your code: In your custom wp_attachment_link() function, you should use the post slug ($attachment->post_name) instead of simply replacing the (whitespaces) with – (dash) in the post title — and note that the resulting slug could be different than the actual slug, e.g. the title could be My Image with the … Read more
After a long search, I finally found the error. It is necessary to use require “/path/to/wordpress/wp-load.php”; to enable wordpress functions in scripts.
The most basic option I can think of is this add_shortcode(‘bt_featured_image_acf_location’, ‘bt_featured_image_acf_location’); function bt_featured_image_acf_location ($atts) { return get_field(‘location’, get_post_thumbnail_id()); } Change ‘location’ to your acf field name and thats it. get_post_thumbnail_id() will get the current post featured image id. Once you have the ID of the post (images are posts, they are of the post … Read more
If you look at the documentation for the media endpoint, you’ll see there’s a field, post, that you can use to attach media to a post using its ID. post The ID for the associated post of the attachment.
You can use DOMDocument to get every image from any page: function testingdom(){ $dom = new DOMDocument(); libxml_use_internal_errors(true); $dom->loadHTMLFile(‘https://the_post_url.com/anyone’); $data = $dom->getElementsByTagName(“img”); $srcs = array(); foreach($data as $key => $dat){ $srcs[] = $data->item($key)->getAttribute(“src”); } $dom = null; } add_action(“wp_head”, “testingdom”); This way you should have every src in an array called srcs