I think there is some problem with your code. I debug your code and find out the problem. Your main problem first of wrong way to enqueue scripts, then custom post type register, and jquery writing style. After fixing working it.
functions.php
// enqueue scripts & style
function ec_theme_scripts(){
wp_enqueue_style('style', get_stylesheet_uri());
wp_enqueue_style('bootstrap', get_template_directory_uri() . '/css/bootstrap.min.css');
wp_enqueue_style('custom-css', get_template_directory_uri() . '/css/style.css');
wp_enqueue_style('slick-css', get_template_directory_uri() . '/css/slick.css');
wp_enqueue_style('fontawesome-css', 'https://pro.fontawesome.com/releases/v5.15.4/css/all.css');
wp_enqueue_script('bootstrap', get_template_directory_uri() . '/js/bootstrap.min.js', array('jquery'), true);
wp_enqueue_script('slick', get_template_directory_uri() . '/js/slick.min.js', array('jquery'), true);
}
add_action('wp_enqueue_scripts', 'ec_theme_scripts');
// Register Custom Post Type
function testimonials_post_register(){
$labels = array(
'name' => _x('Testimonials', 'text_domain'),
'singular_name' => _x('testimonials', 'text_domain'),
'menu_name' => __('Testimonials', 'text_domain'),
'name_admin_bar' => __('Testimonial', 'text_domain'),
'archives' => __('Item Archives', 'text_domain'),
'attributes' => __('Item Attributes', 'text_domain'),
'parent_item_colon' => __('Parent Item:', 'text_domain'),
'all_items' => __('All Items', 'text_domain'),
'add_new_item' => __('Add New Item', 'text_domain'),
'add_new' => __('Add New', 'text_domain'),
'new_item' => __('New Item', 'text_domain'),
'edit_item' => __('Edit Item', 'text_domain'),
'update_item' => __('Update Item', 'text_domain'),
'view_item' => __('View Item', 'text_domain'),
'view_items' => __('View Items', 'text_domain'),
'search_items' => __('Search Item', 'text_domain'),
'not_found' => __('Not found', 'text_domain'),
'not_found_in_trash' => __('Not found in Trash', 'text_domain'),
'featured_image' => __('Featured Image', 'text_domain'),
'set_featured_image' => __('Set featured image', 'text_domain'),
'remove_featured_image' => __('Remove featured image', 'text_domain'),
'use_featured_image' => __('Use as featured image', 'text_domain'),
'insert_into_item' => __('Insert into item', 'text_domain'),
'uploaded_to_this_item' => __('Uploaded to this item', 'text_domain'),
'items_list' => __('Items list', 'text_domain'),
'items_list_navigation' => __('Items list navigation', 'text_domain'),
'filter_items_list' => __('Filter items list', 'text_domain'),
);
$args = array(
'label' => __('testimonials', 'text_domain'),
'description' => __('', 'text_domain'),
'labels' => $labels,
'supports' => array('title', 'editor', 'thumbnail'),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
);
register_post_type('Testimonials', $args);
}
add_action('init', 'testimonials_post_register', 0);
function create_testimonials_shortcode(){
$args = array(
'post_type' => 'testimonials',
'publish_status' => 'published',
);
$query = new WP_Query($args);
if ($query->have_posts()) :
?>
<div class="testimonial_slider">
<?php while ($query->have_posts()) :
$query->the_post();
?>
<div class="testimonial-slide">
<div class="testimonial-content">
<p> <?php the_content(); ?> </p>
</div>
<div class="image-title-wrapper">
<?php $img_url = get_the_post_thumbnail_url(get_the_ID(), 'full'); ?>
<img src="<?php echo $img_url; ?>">
<h4 class="testimonial-name"> <?php the_title(); ?> </h4>
</div>
</div>
<?php endwhile; ?>
</div>
<?php
endif;
wp_reset_postdata();
?>
<?php
}
add_shortcode('testimonials', 'create_testimonials_shortcode');
function testimonials_init(){
?>
<script>
(function($) {
$('.testimonial_slider').slick({
infinite: true,
slidesToShow: 1,
slidesToScroll: 1,
dots: true,
autoplay: true,
autoplaySpeed: 5000
});
})(jQuery);
</script>
<?php
}
add_action('wp_footer', 'testimonials_init');
I think hopefully work it. You can add some style for better look. I added little bit CSS. you can place it into customizer custom CSS or style.css
.image-title-wrapper img {
width: 150px;
height: 150px;
}
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
JavaScript is a multi-paradigm language that supports event-driven, functional, and mandatory (including object-oriented and prototype-based) programming types. Originally JavaScript was only used on the client side. JavaScript is now still used as a server-side programming language. To summarize, we can say that JavaScript is the language of the Internet.
https://www.javascript.com/
JQuery is arguably the most popular JavaScript library with so many features for modern development. JQuery is a fast and concise JavaScript library created by John Resig in 2006. It is a cross-platform JavaScript library designed to simplify client-side HTML scripting. Over 19 million websites are currently using jQuery! Companies like WordPress, Facebook, Google, IBM and many more rely on jQuery to provide a kind of web browsing experience.
https://jquery.com/
CSS (Cascading Style Sheets) is a formal language for describing the appearance of a document written using a markup language.
It is mainly used as a means of describing, decorating the appearance of web pages written using HTML and XHTML markup languages, but can also be applied to any XML documents, such as SVG or XUL.
https://www.w3.org/TR/CSS/#css
Bootstrap is not exclusively a CSS framework, but its most popular features are CSS-centric. These include a powerful grid, icons, buttons, map components, navigation bars, and more.
https://getbootstrap.com/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.