I'm using NextGen for some galleries and noticed that since loading this plugin, in the edit page area under the Featured Image Meta box there is now a link to "Set NextGEN Featured Image". I don't want to confuse the user (by having two "set featured image" links, so I'd like to remove the NextGEN option, leaving only the one default WP link to set the featured image.
I've found tutorials on how to change the text of the standard WordPress "Set Featured Image" Meta Box, but nothing on how to remove the NextGEN link, (I did find a post for adding a plugin to remove it: http://wordpress.org/support/topic/remove-set-nextgen-featured-image)
However, I would like to just remove it in my functions.php file (not use a plugin).
I've tried the following in my functions.php file:
remove_meta_box
remove_filter
remove_action
But I'm not 100% sure which I need to use (none have worked so far).
The file that is adding this function to the page edit area is: https://github.com/mneuhaus/foo/blob/master/nextgen-gallery/products/photocrati_nextgen/modules/ngglegacy/lib/post-thumbnail.php.
I realize that I would just comment out the text in this file that produces the link, but if I ever updated the plugin it would be overwritten.
Any help or suggestions are greatly appreciated! Thank you.
If you don't have/need anything customized for the Featured Image meta box, you can simply remove all filters:
function so_23984689_remove_nextgen_post_thumbnail_html() {
remove_all_filters( 'admin_post_thumbnail_html' );
}
add_action( 'do_meta_boxes', 'so_23984689_remove_nextgen_post_thumbnail_html' );
If there are any other filters, which you would want to keep, you have to loop through the filter array and remove the according element:
function so_23984689_remove_nextgen_post_thumbnail_html() {
global $wp_filter;
if ( ! isset( $wp_filter[ 'admin_post_thumbnail_html' ] ) ) {
return;
}
foreach ( $wp_filter[ 'admin_post_thumbnail_html' ] as $priority => $filters ) {
foreach ( $filters as $id => $filter ) {
if (
isset( $filter[ 'function' ] )
&& is_object( $filter[ 'function' ][ 0 ] )
&& $filter[ 'function' ][ 0 ] instanceof nggPostThumbnail
) {
unset( $wp_filter[ 'admin_post_thumbnail_html' ][ $priority ][ $id ] );
}
}
}
}
add_action( 'do_meta_boxes', 'so_23984689_remove_nextgen_post_thumbnail_html' );
Related
I found this 2 year old solution that essentially counts the and removes the loading attribute where the count =1 and implimented via snippets plugin for Wordpress.
Unfortunately GTMetrix is still flagging "don't lazy load LCP" and when I inspect the image in my browsers I still see the attribute loading="lazy" for the 1st (and every) image on every post.
I suspected it was counting the site logo in the header as the 1st image but it too has loading="lazy" so it seems that the code isn't working at all.
Wordpress 6.0.1
Theme: Hello Elementor Child
Elementor + Elementor Pro
JetEngine for custom post type
Imagify for webP conversion & optimization
I'm not running any lazy-loading plugin and don't want to disable wordpress's global lazy load for all images, just the one above the fold in the LCP.
Snippet I'm running:
/* Remove lazy load first image */
function add_responsive_class($content)
{
if ( is_single() || is_page() || is_front_page() || is_home() )
{
$content = mb_convert_encoding($content, 'HTML-ENTITIES', "UTF-8");
$document = new DOMDocument();
libxml_use_internal_errors(true);
$document->loadHTML(utf8_decode($content));
$imgs = $document->getElementsByTagName('img');
$img = $imgs[0];
if ($imgs[0] == 1)
{ // Check first if it is the first image
$img->removeAttribute( 'loading' );
$html = $document->saveHTML();
return $html;
}
else
{
return $content;
}
}
else
{
return $content;
}
}
add_filter ('the_content', 'add_responsive_class');
If anyone can help me understand why this doesn't work on my site or has a different solution I'd appreciate the help.
Better if you give a higher priority to your filter. It could be that you try to remove something that still doesn't exist.
Elementor is responsible for the output of the image, and it may filter the content after your filter and add the loading parameter after your filter.
As a side note, you can't know if all the first images are always visible. Imagine for example an accordion, or something similar. I don't say that your script is not useful, but that it doesn't always guarantee the best results. Be sure you don't have hidden images. This may also be the cause of the failure of your script. Maybe you are removing the loading parameter to the first hidden images.
In the case of a hidden image, it would be better if they are lazy-loaded.
But if in your specific case, you are sure, then you should not have issues. In that case, check the priority of the filter.
You can also give the possibility in the Elementor editor to remove the lazy load. You can use this code:
add_action( 'elementor/element/image/section_image/before_section_end', function( $element, $args ) {
$element->start_injection( [
'at' => 'after',
'of' => 'link',
] );
$element->add_control(
'my_image_lazy_loading',
[
'label' => __( 'Lazy Loading','lazy-load-control-for-elementor' ),
'type' => \Elementor\Controls_Manager::SELECT,
'default' => 'lazy',
'options' => [
'lazy' => __( 'Lazy load','lazy-load-control-for-elementor' ),
'no_lazy' => __( 'Do not lazy load','lazy-load-control-for-elementor' ),
],
]
);
$element->end_injection();
}, 10, 2 );
add_action( 'elementor/widget/render_content', function( $content, $widget ){
if( $widget->get_name() === 'image' ){
$settings = $widget->get_settings();
if( isset( $settings['my_image_lazy_loading'] ) && 'no_lazy' === sanitize_text_field( $settings['my_image_lazy_loading'] ) ){
$content = str_replace( ' loading="lazy"','',$content );
}
}
return $content;
}, 10, 2 );
Then the user can decide which images should not be lazy loaded.
I am using Advanced Custom Fields Pro and ACF Frontend.
I am trying to remove the image from wordpress media library when a user deletes the image from the image field.
This is what I did:
//ACF Remove Image From WP Media Library
function delete_image( $value, $post_id, $field ) {
$old_value = get_field( $field['local-avatar'], $post_id, false /* Don't format the value, we want the raw ID */ );
if ( $old_value && ( int ) $old_value !== ( int ) $value )
wp_delete_attachment( $old_value, true );
return $value;
}
add_filter( 'acf/update_value/type=image', 'delete_image', 10, 3 );
I got to this by googling:
https://wordpress.stackexchange.com/questions/199887/wordpress-acf-delete-image-from-media-library
Furthermore, to find a solution, I also searched and documented myself on: https://www.advancedcustomfields.com/resources/
Unfortunately it's not working for me, I don't understand what I'm doing.
I am new to Wordpress and php, does anyone have any idea how to solve this problem ?
in my custom post type (documents), I want to change the default page title (not the meta title) to a custom title. I tried several posts about it but it never works. Here'S what I have so far:
add_filter( 'post_type_archive_title', function( $title ) {
if ( is_category( 'documents' ) ) {
$title = 'Bibiliothèque virtuelle';
}
return $title;
}, 50 );
But I still see the default title
Any help would be greatly appreciated!
Perfect woocommerce brands only allows certain tags to be used and removes the rest via the function
if( isset( $_POST['pwb_brand_description_field'] ) ){
$desc = strip_tags(
wp_unslash( $_POST['pwb_brand_description_field'] ),
'<p><span><a><ul><ol><li><h1><h2><h3><h4><h5><h6><pre><strong><em><blockquote><del><ins><img><code><hr>'
);
global $wpdb;
$wpdb->update( $wpdb->term_taxonomy, [ 'description' => $desc ], [ 'term_id' => $term_id ] );
I am looking for a way to overide this so that I can include all tags, in particular <div>
I was hoping there might be something that I could add to functions.php which would help me achieve this?
Because the plugin author did not add any filters / hooks for this particular function, you have to do a fairly clunky work-around.
Thankfully, this function is called via a couple of actions
add_action( 'edit_pwb-brand', array( $this, 'add_brands_metafields_save' ) );
add_action( 'create_pwb-brand', array( $this, 'add_brands_metafields_save' ) );
That means that we may be able to add our own actions that run after those two, and may be able to do what you want.
Note that this is sub-optimal but cannot be avoided. This function is essentially running twice (the original in the plugin, plus yours), which is not good for performance - however, since this is only happening when an admin saves a brand, it shouldn't be too bad for performance.
First, add your own action(s) with a higher priority, then copy the original function with the desired modifications.
It's often recommended that you do this in your theme's functions.php file, but that's not ideal - what if you want to change themes, or update themes, but keep this functionality? Instead, I strongly recommended you build your own small, light-weight plugin. The complete code for such a plugin is below. (Simply add this code to a PHP file, and place it in your plugins directory).
<?php
/**
* Plugin Name: Override Perfect WooCommerce Brands Meta
* Description: Custom override to permit div tags in brand meta description
* Version: 1.0.0
* Author: SupGen
*/
// Note the higher priority levels - to ensure these run AFTER the main plugin is done
add_action( 'edit_pwb-brand', 'override_add_brands_metafields_save', 9999 );
add_action( 'create_pwb-brand', 'override_add_brands_metafields_save', 9999 );
function override_add_brands_metafields_save( $term_id ) {
// NOTE: hard-coding the file name here in order to verify the nonce. MAY need to be changed
$filename = 'class-brands-custom-fields.php';
if ( ! isset( $_POST[ 'pwb_nonce' ] ) || ! wp_verify_nonce( $_POST[ 'pwb_nonce' ], $filename ) ) {
return;
}
// removed bits you didn't care about, keeping only the relevant part
if ( isset( $_POST[ 'pwb_brand_description_field' ] ) ) {
// added div tag to allowed tags list
$desc = strip_tags(
wp_unslash( $_POST[ 'pwb_brand_description_field' ] ),
'<div><p><span><a><ul><ol><li><h1><h2><h3><h4><h5><h6><pre><strong><em><blockquote><del><ins><img><code><hr>'
);
global $wpdb;
$wpdb->update( $wpdb->term_taxonomy, [ 'description' => $desc ], [ 'term_id' => $term_id ] );
}
}
I have created a short code to display short description in woo commerce but it is not working on all posts. It is displaying the short description on some posts and not on others.
Function to create that short code in functions.php
function product_shortdesc_shortcode( $atts ){
// use shortcode_atts() to set defaults then extract() to variables
extract( shortcode_atts( array( 'id' => false ), $atts ) );
// if an $id was passed, and we could get a Post for it, and it's a product....
if ( ! empty( $id ) && null != ( $product = get_post( $id ) ) && $product->post_type = 'product' ){
// apply woocommerce filter to the excerpt
echo apply_filters( 'woocommerce_short_description', $product->post_excerpt );
}
}
// process [product_shortdesc] using product_shortdesc_shortcode()
add_shortcode( 'product_shortdesc', 'product_shortdesc_shortcode' );
The way i am getting the data in my single.php file
$custom = get_post_custom(get_the_ID());
$my_custom_field = $custom['woo_id'];
foreach ( $my_custom_field as $key => $value ) {
echo do_shortcode('[product_shortdesc id='.$value.']');
}
PS: in my normal post i have a custom field which has the value of product id of the product in woo commerece.
Your issue is that you are expecting shortcodes to function which no longer exist. On new installs, these pages won't be created, but if you are updating you may already have those pages in place.
Although the upgrade script does attempt to trash them for you, this might not have happened if they were customised. Delete them. Delete edit-account and change password, then go to your 'my account' page and click the change password/edit account links. You'll be taken to and endpoint which offers the same functionality.
Thanks
Short Code must not echo code instead return the things that needs to be rendered
Change this
echo apply_filters( 'woocommerce_short_description', $product->post_excerpt );
to
return apply_filters( 'woocommerce_short_description', $product->post_excerpt );