• Resolved amexing

    (@amexing)


    I am using a theme where there is an option to enable read more link using jquery. When I click on read more link, it expands full content of the post without opening the post.

    I want to know if it is possible to expand the post by default without clicking on red more link. Could you please help me to achieve this.

    Here is the link of image – https://i.stack.imgur.com/TlUnF.png

    I would also like to know where and how to customize the jquery in child theme.

    • This topic was modified 4 years, 11 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Everything else WordPress topic

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Is your theme Discy? If so, that’s a premium theme from ThemeForest, so you’ve paid for support, available here: https://themeforest.net/item/discy-social-questions-and-answers-wordpress-theme/19281265/support.

    From what I can tell, clicking on “Read more” or “Read less” just toggles the display property of p.excerpt-question and div.content-question-jquery.discy_hide, so using CSS or jQuery it should be simple to start with the full question open.

    Maybe you should look at wordpress REST API. The purpose of the REST api is to allow interaction between the front and back end of your site. You would also want to create a nonce to prevent cross site scripting.

    Thread Starter amexing

    (@amexing)

    Hi @crstauf thanks for your time, Yes i am using Discy theme but they dont support any customization and my support has expired. I tried CSS but that doesnt help/work.

    I got below update from another forum, but i have never customized jQuery before so dont have any idea where to place this code, which file i have to update.

    jQuery(document).ready(function(){
            jQuery(".post-read-more").each(function(){
                jQuery(this).click();
            });
            // And if you want to finally disable this links
            jQuery(".question-read-more").remove();
            jQuery(".question-read-less").remove();
        });

    Would highly appreciate further assistance on this.

    Thanks

    In your theme’s functions.php, or in an mu-plugin, add the following:

    wp_add_inline_script( 'jquery-core', 'jQuery( document ).ready( function() { jQuery( '.post-read-more' ).each( function() { jQuery ( this ).click(); } ); } );' );

    The above should help you get started.

    Thread Starter amexing

    (@amexing)

    Hi @crstauf

    Thanks for the code. I got below error when copied the code to function

    Your PHP code changes were rolled back due to an error on line 190 of file wp-content/themes/discy-child-theme/functions.php. Please fix and try saving again.

    syntax error, unexpected ” ).each( function() { jQuery ‘ (T_CONSTANT_ENCAPSED_STRING), expecting ‘)’

    Thanks

    Oh yeah sorry @amexing: that’s what I get for writing the code plainly.

    wp_add_inline_script( 'jquery-core', 'jQuery( document ).ready( function() { jQuery( ".post-read-more" ).each( function() { jQuery ( this ).click(); } ); } );' );

    Thread Starter amexing

    (@amexing)

    Thanks @crstauf

    This worked like a charm!!

    Glad to have been of help!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to enable read more by default using jquery’ is closed to new replies.