WordPress.org

Forums

Function working in theme but not child theme (4 posts)

  1. su1
    Member
    Posted 1 year ago #

    I'm trying to add featured images to my RSS feed, on a blog running a pinbin child theme.

    - When I install and activate the plugin "Add featured image to RSS feed" it works.
    - When I try to paste the code of this plugin in my functions.php file it works
    - When I try to paste the code of this plugin in my child functions.php file it doesn't work (the featured image is not added to the rss feed).

    The code is

    function add_featured_image_to_feed($content) {
        global $post;
        if ( has_post_thumbnail( $post->ID ) ){
            $content = '' . get_the_post_thumbnail( $post->ID, 'large' ) . '' . $content;
        }
        return $content;
    }
    
    add_filter('the_excerpt_rss', 'add_featured_image_to_feed', 1000, 1);
    add_filter('the_content_feed', 'add_featured_image_to_feed', 1000, 1);

    What could I be doing wrong? Of course my blog is using the child theme and I've checked that other functions in the child functions.php file are working.

  2. Pioneer
    Member
    Posted 1 year ago #

    Did you remove the code from the parent theme before using in Child Theme?

  3. su1
    Member
    Posted 1 year ago #

    yes I did that - no conflict of functions possible.

  4. Pioneer
    Member
    Posted 1 year ago #

    Some plugins/code make hooks into the theme in use incorrectly (do not note use of a child theme), like getting the wrong stylesheet directory, try what is noted here:

    http://codex.wordpress.org/Function_Reference/has_post_thumbnail

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags