Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #672349

    Hi, I have a couple of post categories (news and video) and I would like to change the text ‘Read More’ to ‘Watch the video’ only for those posts that belong to that category. Can it be done with a function without touching core files? Thank you.

    #673964

    Hey Alberto,

    Thank you for using Enfold

    What is the actual slug of the “video” category? Please add something like this in the functions.php file:

    // custom script
    add_action( 'wp_footer', 'ava_custom_script' );
    function ava_custom_script() {
    	?>
    	<script type="text/javascript">
    	(function($) {
    		function b() {
    			var video = $('body').hasClass('category-video');
    			if(!video) return;
    			$('.more-link').each(function() {
    				$(this).empty();
    				$(this).text('Watch the video');
    			});
    		}
    
    	   	b();
    	})(jQuery);
    	</script>
    	<?php
    }

    Best regards,
    Ismael

    #674158

    My videos are on Vimeo and each shortcode is inside a code block in a post which has the category slug ‘video’. Then I have a gallery/video page which contains the avia article module filtered by the category video so it shows the last 3 article by that category. At the moment there’s no class associated to the videos, but if needed I can add it in the code block. The function should change the text “read more” of the button to ‘watch the video’ only for those articles belonging to the video cat. Then, since the website will be in 3 languages, I guess the easiest way will be to add the line ‘watch the video’ in a .pot file (if it doesn’t exist already) and have it translated accordingly.

    I tried the above function changing ‘category-video’ to ‘video’ (the cat slug) but nothing happens.
    I’m using a child theme of the Gym Demo. Thank you.

    #674588

    Ok, I solved the problem with this function:

    function ava_custom_script() {
    	?>
    	<script type="text/javascript">
    	(function($) {
    		function b() {
    			var video = $('article').hasClass('category-video') || $('article').hasClass('category-video-en');
    			if(!video) return;
    			$('.more-link').each(function() {
    				$(this).empty();
    				$(this).text('Watch the video');
    			});
    		}
    
    	   	b();
    	})(jQuery);
    	</script>
        <?php
    }
    add_action( 'wp_footer', 'ava_custom_script' );
    

    Thank you for putting me on the right track!

    • This reply was modified 8 years, 3 months ago by alby54.
    #674950

    Hi,

    Great, glad you got it working and thanks a lot for sharing your solution :-)

    Regards,
    Rikard

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.