Explore / Programming I want to be sure that every code file of my widget is in order because there are still… Save Share Download ▾ ReportJump to turn (20) 1 I want to be sure that every code file of my widget is in order because there ar 2 FIRST FILE CODE. FILE my-custom-portfolio-widget.php STARTS HERE- =' ) ) { addac 3 before we continue i want to establish the following: Share the Files: I cannot 4 This one is larger so i have to subdivide it in three parts. WAIT THE ANALYSIS A 5 SECOND FILE "widgets/portfolio-list-widget.php" - PART 2 CODE - protected functi 6 SECOND FILE "widgets/portfolio-list-widget.php" - PART 3 CODE - protected functi 7 THIRD FILE "portfolio-list.css" CODE - / General Widget Container / .elementor-w 8 FOURTH FILE "portfolio-list.js" CODE - console.log('portfolio-list.js STARTING E 9 CAN YOU PLEASE GIVE ME THE ENTIRE AND FINAL REVISED VERSION OF THE FIRST FILE? 10 this is simply amazing thanks. lets start with the first issue. 1.- I need a sin 11 PLEASE GIVE ME THE FULL UPDATES FOR EACH FILES. SO I CAN COPY THE UPDATES AND PA 12 lets go one by one again....because i dont think this was done correctly. first 13 CURRENT CSS FILE "portfolio-list.css": CODE: / === General Widget Container === 14 please generate the complete updated CSS file text with these fixes included! 15 great, the layout is in order thanks. I have however new issues: 1.- Inside ELEM 16 FOR EACH OF THE STEPS, I WANT YOU TO GIVE ME -THE COMPLETE- CORRECTED SECTION OF 17 I HAVE MANY DOUBTS FOR THE FIRST INSTRUCTION, FOR "registercontrols()". Im sahri 18 FOR THE NEXT STEP FOR "render()", IM UNABLE TO SEE WHERE TO MAKE THE CORRECTIONS 19 YES I NEED A LOT OF HELP WITH THE LAST SECTION "contenttemplate()", PLEASE CORRE 20 applied all these changes. None of the issue were solved. I want to be sure that every code file of my widget is in order because there are still a few issues to solve.
would it be a nice idea if i share you the files that you consider the most important from these:
my-custom-portfolio-widget-2/
├── my-custom-portfolio-widget.php ← Main plugin file with author, enqueues, and registration
├── widgets/
│ └── portfolio-list-widget.php ← Elementor widget class
├── assets/
│ ├── css/
│ │ └── portfolio-list.css ← Simple Swiper styles
│ └── js/
│ └── portfolio-list.js ← JS initializing Swiper with Elementor hooks
├── libs/
│ └── swiper/
│ ├── swiper-bundle.min.css ← These files remain the same
│ └── swiper-bundle.min.js
An then you can analyse them, check if everything looks fine, and set it as our new basis and starting point? and from there, continue solving issues. what do you say
Assistant2025-06-16 14:17 UTC Copy response
Copy first prompt Copy first response
Details
Provider OpenAI
Model provenance As recorded by source dataset
Turns 20 (40 messages)
Language en
Conversation date Jun 16, 2025
Added to archive Nov 16, 2026
ID 01m7h42w62yx98mx0z682qwwwjSource & license Imported from WildChat-4.8M (AI2) (source ). Imported records earn no Research Points.
Upstream record: 27f0bb6305161645d8a10cf134c3ca33
Zhao et al., WildChat: 1M ChatGPT Interaction Logs in the Wild (ICLR 2024). Contains information from WildChat-4.8M, made available under the ODC Attribution License.
License: ODC-BY-1.0
That sounds like a great plan!
Sharing the key files will definitely help me understand your widget’s structure and functionality, verify if everything is properly set up, and ensure you have a solid baseline. Once we have a confirmed baseline, fixing current issues or adding improvements will be much smoother.
From your file tree, the most critical files to start with are:
my-custom-portfolio-widget.php (main plugin file that registers and enqueues scripts/styles)
widgets/portfolio-list-widget.php (Elementor widget class - core widget logic)
assets/js/portfolio-list.js (JS initializing Swiper with Elementor hooks)
assets/css/portfolio-list.css (widget-specific styling)
The libs/swiper files are standard library files, so usually no need to share or check those unless you suspect something wrong with them.
Please share these 4 files, and I’ll analyze them for coding standards, best practices, and possible issues. Then we can consider that our verified starting point and continue working on fixing or improving your widget.
Looking forward to your files!
FIRST FILE CODE.
FILE my-custom-portfolio-widget.php STARTS HERE-
Show full message · 163 lines Assistant2025-06-16 14:19 UTC Copy response
Thanks for sharing your main plugin file my-custom-portfolio-widget.php. Here's an analysis about its structure, correctness, and some improvement suggestions:
Overall Impression
This file is well-organized and follows good practices for an Elementor add-on plugin:
Basic plugin header info is present.
Proper checks for Elementor active version and minimum PHP.
Using plugins_loaded hook to defer initialization until plugins are loaded.
Clear separation of registering widgets and enqueueing assets.
Dynamic versioning with filemtime() - good for cache busting in development.
Admin notices for missing dependencies.
Final instantiation at the bottom.
The usage of namespaces in widget registration indicates good care with avoiding class name collisions.
Detailed Points & Suggestions:
1. Namespace Usage
Your widget class is namespaced (MyCustomPortfolio\Widgets\Portfolio_List_Widget) but this file itself isn’t under any namespace. That’s totally fine; the file is procedural, but just keep consistent about naming.
2. Hooks Usage
You’re hooking to:
plugins_loaded for startup checks - perfect.
elementor/widgets/register to register the widget - standard.
elementor/frontend/after_enqueue_scripts for adding frontend scripts/styles - good.
If you want to also enqueue admin/editor scripts/styles specifically for Elementor editor, consider adding:
php Copy code
add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_editor_scripts' ] );
(if you have editor-specific scripts)
3. Error Logging / Debugging
You have several error_log() calls inside enqueue_scripts(). These are useful for debugging but should be removed or wrapped in a conditional debug flag before production. Leaving error logs on live sites causes performance implications and pollutes logs:
php Copy code
if ( defined('WP_DEBUG') && WP_DEBUG ) {
error_log('...');
}
or simply remove them once debugging is complete.
4.
before we continue i want to establish the following:
Share the Files:
I cannot add to this chat the required files. Lets go file by file and ill copy each of these here. Tell me when to share the code of the first one, i'm ready.
code Copy code
Describe Any Known Issues:
For now I wont tell you what issues are there, we will check this after. First lets set the basis. I only want you to examine very well each file and that the code inside is good. I need you to check that everything is in order, that all these files relate to each other well, that check if there are things to improve and/or optimize.
code Copy code
Analysis & Feedback:
I want you that for each file, that you give me back the revised/optimized final versions. This will set the new basis. I dont need much feedback just the overview. I need the files corrected where needed.
Assistant2025-06-16 14:20 UTC Copy response
Understood and perfectly clear!
Let's proceed exactly as you laid out:
You will share each file one by one.
I will carefully analyze it for correctness, consistency, relations with other files, optimizations, and best practices.
Then I will provide back a cleaned-up, revised, or optimized final version of that file.
Minimal feedback overview just to confirm the main points and reasoning.
That will serve as our new solid baseline to continue from.
Please go ahead and share the code of the next file whenever you're ready.
This one is larger so i have to subdivide it in three parts. WAIT THE ANALYSIS AND CORRECTIONS UNTIL I HAVE SHRED THE 3 SUBDIVISIONS.
SECOND FILE "widgets/portfolio-list-widget.php" - PART 1 CODE -
Show full message · 473 lines Assistant2025-06-16 14:22 UTC Copy response
Got it, I will wait for you to share parts 2 and 3 before doing any analysis or corrections. Please continue when you’re ready with part 2.
SECOND FILE "widgets/portfolio-list-widget.php" - PART 2 CODE -
protected function render() {
s e t t i n g s = settings = se tt in g s = this->get_settings_for_display();
i t e m s = items = i t e m s = settings['portfolio_items'];
Show full message · 90 lines Assistant2025-06-16 14:23 UTC Copy response
Understood, awaiting part 3 to complete the entire file before providing analysis and optimized revised code.
Please share part 3 when ready.
SECOND FILE "widgets/portfolio-list-widget.php" - PART 3 CODE -
protected function content_template() {
?>
<#
var settings = settings;
var swiperOptions = {
slidesPerView: settings.slides_per_view,
spaceBetween: settings.space_between,
loop: ( 'yes' === settings.loop_carousel ),
autoplay: ( 'yes' === settings.autoplay ) ? { delay: settings.autoplay_delay } : false,
navigation: ( 'yes' === settings.show_navigation ) ? { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev' } : false,
pagination: ( 'yes' === settings.show_pagination ) ? { el: '.my-custom-swiper-pagination.swiper-pagination', clickable: true } : false,
breakpoints: {
640: {
slidesPerView: 1,
spaceBetween: 20,
},
768: {
slidesPerView: 2,
spaceBetween: 40,
},
1024: {
slidesPerView: settings.slides_per_view,
spaceBetween: settings.space_between,
},
},
};
Show full message · 104 lines Assistant2025-06-16 14:26 UTC Copy response
Thanks for sharing all three parts of widgets/portfolio-list-widget.php.
Analysis and Revised/Optimized Version
I’ve carefully reviewed the entire widget class with these goals:
Correctness: Make sure all features and interactions are logically consistent.
Consistency: Between PHP render and JS content template.
Security: Proper escaping for output.
Optimization: Remove duplication, improve maintainability, and eliminate redundancies.
Best Practices: For Elementor widget coding and Swiper usage.
Overview of Key Observations Before Revision
Controls registration is very thorough and flexible.
Swiper options are built correctly based on settings.
PHP render() method builds the carousel with slides, media, links, and Swiper structure.
JS content_template() mirrors render() logic well.
You smartly included helper methods to extract Youtube/Vimeo IDs—nice encapsulation.
Escape functions are nicely used (minor refinements possible).
Pagination div handling differs between PHP and JS (PHP puts it inside slide footer, JS puts it globally).
Minor markup inconsistencies between PHP and JS versions (e.g., anchors and wrappers).
Suggest extracting media embed logic from render() into dedicated methods to reduce complexity.
Some minor coding style improvements possible.
Revised and Optimized Full portfolio-list-widget.php Code
Show full message · 733 lines
THIRD FILE "portfolio-list.css" CODE -
/* General Widget Container */
.elementor-widget-my-custom-portfolio-list {
position: relative;
width: 100%;
overflow: hidden;
}
/* Swiper Container and Slides */
.my-custom-portfolio-list {
width: 100%;
height: auto;
overflow: hidden;
}
.swiper-slide {
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-start;
padding-bottom: 50px;
width: 100%;
flex-shrink: 0;
}
/* Portfolio Item Structure */
.my-custom-portfolio-list-item {
width: 100%;
display: flex;
flex-direction: column;
align-items: flex-start;
position: relative;
}
.my-custom-portfolio-list-item-wrapper {
position: relative;
display: block;
width: 100%;
height: 100%;
}
/* 1. DISPLAYED IMAGE OR VIDEO */
.my-custom-portfolio-list-item-media {
width: 100%;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
}
.my-custom-portfolio-list-item-media img,
.my-custom-portfolio-list-item-media video {
width: 100%;
height: 100%;
display: block;
}
.my-custom-portfolio-video-embed {
width: 100%;
height: 100%;
position: relative;
padding-bottom: 56.25%;
height: 0;
overflow: hidden;
}
.my-custom-portfolio-video-embed iframe,
.my-custom-portfolio-video-embed object,
.my-custom-portfolio-video-embed embed {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
/* 2. FOOTER WITH TITLE, CATEGORY, AND PAGINATION INLINE */
.my-custom-portfolio-list-item-footer {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
padding-top: 10px;
gap: 20px;
}
.my-custom-title {
flex: 1;
font-weight: bold;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
text-align: left;
}
.my-custom-category {
flex: 2;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
text-align: left;
}
/* 3. INLINE PAGINATION BULLETS */
.my-custom-swiper-pagination.swiper-pagination {
position: relative !important;
width: auto;
display: flex;
align-items: center;
justify-content: flex-end;
margin-left: auto;
padding-left: 10px;
gap: 4px;
}
/* Bullet Styling */
.swiper-pagination-bullet {
background-color: transparent !important;
border: none !important;
opacity: 1 !important;
outline: none;
}
.my-custom-swiper-pagination .swiper-pagination-bullet {
background: #ccc;
opacity: 1;
margin: 0 5px;
position: relative;
width: 1.1rem;
height: .65rem;
border-radius: 999px;
transition: width 0.3s, background-color 0.3s;
}
.my-custom-swiper-pagination .swiper-pagination-bullet-active {
background: #000;
width: 1.1rem;
}
.my-custom-swiper-pagination .swiper-pagination-bullet:focus {
outline: none;
}
/* 4. LINK OVERLAY */
.my-custom-portfolio-link {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 5;
opacity: 0;
}
/* Ensure media and footer remain clickable */
.my-custom-portfolio-list-item-media,
.my-custom-portfolio-list-item-footer {
position: relative;
z-index: 1;
}
Show full message · 176 lines Assistant2025-06-16 14:29 UTC Copy response
Thanks for sharing the CSS file. Here's a concise review and a lightly cleaned-up final version with some minor improvements for clarity and consistency:
Review Summary
The CSS is well-structured using comments, making it clear and maintainable.
The selectors are specific enough to avoid conflicts.
The .my-custom-portfolio-link overlay technique is good for clickable coverage without interfering with content display.
Pagination bullets styling is customized nicely.
Responsive adjustments included for smaller screens.
No major issues found.
Minor Improvements made:
Added consistent spacing and indentation.
Added fallback height for .my-custom-portfolio-video-embed to handle potential zero height fallback.
Added box-sizing: border-box; to .swiper-slide and .my-custom-portfolio-list-item for better sizing control.
Removed some redundant/overriding rules (height: auto; already default for .my-custom-portfolio-list).
Comment clarity enhancements.
Revised portfolio-list.css
Show full message · 209 lines
FOURTH FILE "portfolio-list.js" CODE -
console.log('portfolio-list.js STARTING EXECUTION!'); // Add this line
(function ($) {
'use strict';
console.log('portfolio-list.js is running!'); // Add this line
code Copy code
var initPortfolioSwipers = function () {
var swiperContainers = $('.my-custom-portfolio-list.swiper-container');
if (swiperContainers.length) {
swiperContainers.each(function () {
var $this = $(this);
var swiperOptions = $this.data('swiper-options') || {};
if (swiperOptions.navigation && typeof swiperOptions.navigation === 'object') {
swiperOptions.navigation.nextEl = $this.find('.swiper-button-next')[0];
swiperOptions.navigation.prevEl = $this.find('.swiper-button-prev')[0];
}
if (swiperOptions.pagination && typeof swiperOptions.pagination === 'object') {
swiperOptions.pagination.el = $this.find('.swiper-pagination')[0];
}
// Ensure Swiper is available globally or initialize locally if needed
// Elementor usually ensures Swiper is loaded, but this is a fallback
if (typeof Swiper !== 'undefined') {
new Swiper($this[0], swiperOptions);
} else {
console.warn('Swiper library not found. Please ensure it is enqueued.');
}
});
}
};
// Initialize on document ready for initial page load
$(document).ready(function () {
initPortfolioSwipers();
});
// Initialize when Elementor editor is ready and for widget rendering
$(window).on('elementor/frontend/init', function () {
elementorFrontend.hooks.addAction('frontend/element_ready/portfolio-list-widget.default', initPortfolioSwipers);
});
})(jQuery);
Show full message · 45 lines Assistant2025-06-16 14:30 UTC Copy response
Thanks for sharing your JS file. Here's a concise review and an optimized final version:
Review Summary
The script correctly initializes all .my-custom-portfolio-list swiper containers.
Reads swiper options from data-swiper-options attribute.
Properly assigns navigation and pagination elements scoped inside each container.
Checks globally for Swiper availability, logging warning if missing.
Initializes on both document ready and via Elementor frontend widget hooks for editor render.
The console logs are useful for debugging but should be conditioned before production.
Minor Improvements
Wrap debug console.log and console.warn messages in a debug flag or remove for production.
Cache jQuery selectors ($this.find(...)) into variables for readability.
Use optional chaining (?) cautiously: your code is jQuery based, so keep safe with vanilla checks.
Add semicolons where missing (mostly stylistic).
Minor comment polish.
Final Optimized portfolio-list.js
CAN YOU PLEASE GIVE ME THE ENTIRE AND FINAL REVISED VERSION OF THE FIRST FILE?
Assistant2025-06-16 14:31 UTC Copy response
Certainly! Here is the entire revised and optimized final version of your my-custom-portfolio-widget.php file, cleaned up and ready as a solid foundation:
Show full message · 210 lines this is simply amazing thanks. lets start with the first issue.
1.- I need a single horizontal line layout of the "title" "categories" and "pagination dots" in a single line beneath the media, like this:
[Title (left)] [Categories (centered ~65%)] [Pagination dots (right)]
But currently:
• ✅ Title is correctly on the left.
• ❌ Categories are too far right (hugging the right edge).
• ❌ Pagination dots are below the others — not inline.
⸻
🎯 Goal: One horizontal row with 3 zones
• Left: Title
• Middle (~65% width): Categories
• Right: Swiper pagination bullets
YOU HAVE GIVEN ME ALL THE FILES AS OPTIMIZED AND REVISED. CAN YOU NOW GIVE ME THE SURGICALLY PART TO CORRECT IN EACH FILE/FILES TO HAVE THIS ISSUE SOLVED? OR BETTER YET, CAN YOU WRITE DOWN THE ENTIRE FILE OR FILES I MUST REPLACE TO HAVE THIS ISSUE CORRECTED? PLEASE DONT UPLOAD A FILE TO DOWNLOAD, IS BEST TO KEEP WIRTING HERE THE CODE TO COPY AND PASTE.
Assistant2025-06-16 14:45 UTC Copy response
Great! Let's fix the layout of the footer row below the media so you get exactly this:
Left: Title
Middle (~65% width): Category
Right: Pagination dots
Where to change
The relevant markup and CSS are spread over two files:
widgets/portfolio-list-widget.php → the footer rendering markup inside the render() method
assets/css/portfolio-list.css → styles for .my-custom-portfolio-list-item-footer, .my-custom-title, .my-custom-category, .my-custom-swiper-pagination
Step 1: Update PHP Render Footer markup in portfolio-list-widget.php
Replace just the footer part inside the loop in the render() method with the following code:
php Copy code
<div class="my-custom-portfolio-list-item-footer">
<div class="my-custom-title" style="flex: 1; text-align: left;">
<?php echo esc_html( $item['portfolio_item_title'] ); ?>
</div>
<div class="my-custom-category" style="flex: 0 0 65%; text-align: center;">
<?php echo esc_html( $item['portfolio_item_category'] ); ?>
</div>
<?php if ( 'yes' === $settings['show_pagination'] ) : ?>
<div class="my-custom-swiper-pagination swiper-pagination" style="flex: 0 0 auto; text-align: right;"></div>
<?php endif; ?>
</div>
What changed?
.my-custom-portfolio-list-item-footer is a flex container already, so inside it:
Title gets flex: 1 and left-aligned text.
Category gets fixed width approx 65% (flex: 0 0 65%) and centered text.
Pagination dots get a flex: 0 0 auto so they won't shrink and align right.
Pagination dots moved inside the footer container instead of below.
Step 2: Update styles in portfolio-list.css
PLEASE GIVE ME THE FULL UPDATES FOR EACH FILES. SO I CAN COPY THE UPDATES AND PASTE ACCORDINGLY. YOU WILL TELL ME:
EXACTLY WHAT DO I HAVE TO REPLACE IN EACH FILE
-TE CORRECTED CODE TO IMPLEMENT, INSTEAD OF THE PREVIOUS THAT MAKES THIS ISSUE.
Assistant2025-06-16 14:48 UTC Copy response
Absolutely! Below are full precise replacements for the relevant parts in the two files you need to edit — so you can directly copy/paste and fix the horizontal footer layout issue.
1) widgets/portfolio-list-widget.php
What to replace?
Replace the footer rendering markup inside the foreach loop in the render() method.
Look for this block in your render() method in the loop over slides (the old footer):
php Copy code
<!-- Footer Row with Title, Category, and Pagination (inline) -->
<div class="my-custom-portfolio-list-item-footer">
<div class="my-custom-title"><?php echo esc_html( $item['portfolio_item_title'] ); ?></div>
<div class="my-custom-category"><?php echo esc_html( $item['portfolio_item_category'] ); ?></div>
<?php if ( 'yes' === $settings['show_pagination'] ) : ?>
<div class="my-custom-swiper-pagination swiper-pagination"></div>
<?php endif; ?>
</div>
Replace it entirely with this:
php Copy code
<div class="my-custom-portfolio-list-item-footer">
<div class="my-custom-title" style="flex: 1; text-align: left; color: <?php echo esc_attr( $settings['title_color'] ); ?>; <?php echo $this->get_inline_typography_css( $settings, 'title_typography' ); ?>">
<?php echo esc_html( $item['portfolio_item_title'] ); ?>
</div>
<div class="my-custom-category" style="flex: 0 0 65%; text-align: center; color: <?php echo esc_attr( $settings['category_color'] ); ?>; <?php echo $this->get_inline_typography_css( $settings, 'category_typography' ); ?>">
<?php echo esc_html( $item['portfolio_item_category'] ); ?>
</div>
<?php if ( 'yes' === $settings['show_pagination'] ) : ?>
<div class="my-custom-swiper-pagination swiper-pagination" style="flex: 0 0 auto; text-align: right;"></div>
<?php endif; ?>
</div>
lets go one by one again....because i dont think this was done correctly.
first with the first file and "render()" section. I will copy here the entire render section. give me back the entire rectified version of it. I think you made a mistake in your previous response becasue i did not find the section that you established.
CURRENT CODE:
protected function render() {
s e t t i n g s = settings = se tt in g s = this->get_settings_for_display();
i t e m s = items = i t e m s = settings['portfolio_items'];
Show full message · 104 lines Assistant2025-06-16 14:55 UTC Copy response
Thanks for sharing the full current render() method! Below is the full corrected and optimized version of your render() method implementing exactly what you want:
Footer row with three zones in a horizontal line below the media:
Title on left (flex: 1, left-aligned)
Category in center (~65% width, centered)
Pagination dots on right (flex shrink 0)
Pagination dots rendered once per slider outside of slides loop, inside the main container but below .swiper-wrapper.
FULL REVISED render() METHOD
CURRENT CSS FILE "portfolio-list.css":
CODE:
/* === General Widget Container === */
.elementor-widget-my-custom-portfolio-list {
position: relative;
width: 100%;
overflow: hidden;
}
/* === Swiper Container and Slides === */
.my-custom-portfolio-list {
width: 100%;
overflow: hidden;
}
.swiper-slide {
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-start;
padding-bottom: 50px;
width: 100%;
flex-shrink: 0;
box-sizing: border-box;
}
/* === Portfolio Item Structure === */
.my-custom-portfolio-list-item {
width: 100%;
display: flex;
flex-direction: column;
align-items: flex-start;
position: relative;
box-sizing: border-box;
}
.my-custom-portfolio-list-item-wrapper {
position: relative;
display: block;
width: 100%;
height: 100%;
}
/* === Displayed Image or Video === */
.my-custom-portfolio-list-item-media {
width: 100%;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
}
.my-custom-portfolio-list-item-media img,
.my-custom-portfolio-list-item-media video {
width: 100%;
height: 100%;
display: block;
}
.my-custom-portfolio-video-embed {
position: relative;
width: 100%;
/* Maintain 16:9 aspect ratio /
padding-bottom: 56.25%;
height: 0;
overflow: hidden;
min-height: 150px; / fallback height */
}
.my-custom-portfolio-video-embed iframe,
.my-custom-portfolio-video-embed object,
.my-custom-portfolio-video-embed embed {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
/* === Footer with Title, Category, and Pagination Inline === */
.my-custom-portfolio-list-item-footer {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
padding-top: 10px;
gap: 20px;
}
.my-custom-title {
flex: 1;
font-weight: bold;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
text-align: left;
}
.my-custom-category {
flex: 2;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
text-align: left;
}
/* === Inline Pagination Bullets === */
.my-custom-swiper-pagination.swiper-pagination {
position: relative !important;
width: auto;
display: flex;
align-items: center;
justify-content: flex-end;
margin-left: auto;
padding-left: 10px;
gap: 4px;
}
/* Pagination bullet styling */
.swiper-pagination-bullet {
background-color: transparent !important;
border: none !important;
opacity: 1 !important;
outline: none;
}
.my-custom-swiper-pagination .swiper-pagination-bullet {
background: #ccc;
opacity: 1;
margin: 0 5px;
position: relative;
width: 1.1rem;
height: 0.65rem;
border-radius: 999px;
transition: width 0.3s, background-color 0.3s;
}
.my-custom-swiper-pagination .swiper-pagination-bullet-active {
background: #000;
width: 1.1rem;
}
.my-custom-swiper-pagination .swiper-pagination-bullet:focus {
outline: none;
}
/* === Link Overlay Cover === */
.my-custom-portfolio-link {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 5;
opacity: 0;
}
Show full message · 179 lines Assistant2025-06-16 14:58 UTC Copy response
Thanks for sharing your current full CSS! Based on the updated HTML structure in the render() method, here’s the corrected CSS snippet you should replace/add to achieve the requested horizontal layout of the footer row:
What to replace in your CSS:
Replace the entire block for:
css Copy code
.my-custom-portfolio-list-item-footer {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
padding-top: 10px;
gap: 20px;
}
.my-custom-title {
flex: 1;
font-weight: bold;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
text-align: left;
}
.my-custom-category {
flex: 2;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
text-align: left;
}
Replace it with this updated CSS block :
css Copy code
.my-custom-portfolio-list-item-footer {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
padding-top: 10px;
gap: 10px; /* tighter gap */
}
/* Title on the left */
.my-custom-title {
flex: 1;
font-weight: bold;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
text-align: left;
}
/* Category centered and approx 65% width */
.my-custom-category {
flex: 0 0 65%; /* do not grow or shrink, takes 65% width */
text-align: center;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
Explanation:
.my-custom-category now has flex: 0 0 65%; so it takes roughly 65% width and is centered.
Gap is somewhat tightened from 20px to 10px for a balanced look.
please generate the complete updated CSS file text with these fixes included!
Assistant2025-06-16 14:58 UTC Copy response
Certainly! Here is the complete updated portfolio-list.css file incorporating the fixes for the footer layout and keeping all your existing styles intact:
great, the layout is in order thanks.
I have however new issues:
1.- Inside ELEMENTOR, when I try to modify my widget in the Style tab, I cannot change the font format/ typography of the [Title (left)] or [Categories (centered ~65%)]. I have tried to move slidrers, change font, font size. There is something not working. (MOST IMPORTANT PROBLEM)
2.-The widget is NOT RENDERING inside ELEMENTOR in live the changes I do.
3.-The widget is NOT RENDERING inside ELEMENTOR in live each of the Prtfolio the items, just the very first one. Although pagination dots are present, is not rendering it. HOWEVER. In the live version of the site i'm able to see the changes.
Assistant2025-06-16 15:08 UTC Copy response
Thanks for outlining these new issues clearly! Let’s address them one by one, focusing on why your style controls don’t apply inside Elementor and why live preview/rendering is broken or partial.
1. Typography controls (Style tab) for Title and Category NOT updating inside Elementor editor
Root cause and common mistakes:
Elementor style typography/color controls must be used correctly in both register_controls() and in render() and content_template() templates.
You are applying typography CSS inline in the PHP render() method via $this->get_inline_typography_css(...) which is OK, but:
The JS content_template() must also apply these styles exactly the same way or the live preview in editor won't update styles.
If the JS template (content_template()) does not apply typography control values/styles correctly, Elementor’s live frontend editor will show default/static styles only.
Similarly, applying styles inline as style="..." directly might sometimes override or conflict with Elementor’s dynamic CSS output (which generates scoped CSS selectors automatically based on control IDs).
How to fix typography controls for live preview and Style tab?
Step 1: Match typography use in BOTH PHP render() and JS content_template()
In your PHP render() method you call:
php Copy code
<?php echo $this->get_inline_typography_css( $settings, 'title_typography' ); ?>
But in your content_template() JS method, there’s no equivalent for applying typography styles to the title and category text.
Step 2: Add typography styles in content_template()
In your content_template() (the underscore template JS), apply typography settings inline to the title and category , similar to how you do it in PHP.
Here is the snippet to add/change inside your content_template() method:
Show full message · 195 lines FOR EACH OF THE STEPS, I WANT YOU TO GIVE ME -THE COMPLETE- CORRECTED SECTION OF THE CODE I HAVE TO CHANGE, AND TELL ME SPECIFICALLY IN WHICH PART OF WHICH FILE I MUST PASTE THE CORRECTIONS YOU GIVE ME. IF YOU NEED ME TO GIVE YOU FULL SECTIONS OF CODE THAT YOU NEED TO CORRECT, PLEASE TELL ME. I DONT KNOW HOW TO IMPLEMENT YOUR SOLUTIONS, SO THIS WAY IS MUCH MUCH EASIER FOR ME, JUST COPY, AND REPLACE THE CODE WEHERE NEEDED.
Assistant2025-06-16 15:14 UTC Copy response
Absolutely! I will provide complete corrected sections for each step, specify exactly which file and function/method to replace, along with where to paste them. Just copy & paste!
Step 1: Fix Typography Controls in register_controls()
File:
widgets/portfolio-list-widget.php
Function / Method:
register_controls()
What to do:
Replace your current typography control registrations for title and category typography with the following full corrected blocks .
Find and replace the parts registering:
php Copy code
$this->add_group_control(
\Elementor\Group_Control_Typography::get_type(),
[
'name' => 'title_typography',
'label' => esc_html__( 'Title Typography', 'my-custom-portfolio-widget' ),
'selector' => '{{WRAPPER}} .my-custom-portfolio-list-item-title',
]
);
$this->add_group_control(
\Elementor\Group_Control_Typography::get_type(),
[
'name' => 'category_typography',
'label' => esc_html__( 'Category Typography', 'my-custom-portfolio-widget' ),
'selector' => '{{WRAPPER}} .my-custom-portfolio-list-item-category',
]
);
Paste these in your register_controls() method exactly where current typography controls are.
Step 2: Remove Inline Typography & Color Styles in render() Method
File:
widgets/portfolio-list-widget.php
Function / Method:
render()
What to do:
Replace this part:
Show full message · 243 lines I HAVE MANY DOUBTS FOR THE FIRST INSTRUCTION, FOR "register_controls()". Im sahring the entire section. Please correct it all, and give me the new version with your solutions implemented.
CODE:
protected function register_controls() {
// Content Section
$this->start_controls_section(
'section_content',
[
'label' => esc_html__( 'Portfolio List Content', 'my-custom-portfolio-widget' ),
'tab' => Controls_Manager::TAB_CONTENT,
]
);
Show full message · 397 lines Assistant2025-06-16 15:21 UTC Copy response
Here is your fully corrected and optimized register_controls() method code , integrating the fixes to make the typography controls work properly in Elementor editor and frontend:
Show full message · 411 lines FOR THE NEXT STEP FOR "render()", IM UNABLE TO SEE WHERE TO MAKE THE CORRECTIONS. PLEASE GIVE ME THE ENTIRE RENDER SECTION CORRECTED. THIS IS THE CURRENT CODE.
CODE:
protected function render() {
s e t t i n g s = settings = se tt in g s = this->get_settings_for_display();
i t e m s = items = i t e m s = settings['portfolio_items'];
Show full message · 104 lines Assistant2025-06-16 15:26 UTC Copy response
Certainly! Below is the entire corrected render() method , following best practices for Elementor styling and addressing your issues, particularly:
Removing all inline color and typography styles to enable Elementor's CSS injection via selectors (so your style tab changes work).
Keeping footer layout as desired.
Pagination dots rendered once per slider (outside slides loop).
YES I NEED A LOT OF HELP WITH THE LAST SECTION "content_template()", PLEASE CORRECT THE ENTIRE SECTION AND GIVE BACK THE CORRECTED VERSION ONLY WIHT ALL CORRECTIONS. HERE IS THE CURRENT CODE OF THIS SECTION.
CODE:
protected function content_template() {
?>
<#
var settings = settings;
var swiperOptions = {
slidesPerView: settings.slides_per_view,
spaceBetween: settings.space_between,
loop: ( 'yes' === settings.loop_carousel ),
autoplay: ( 'yes' === settings.autoplay ) ? { delay: settings.autoplay_delay } : false,
navigation: ( 'yes' === settings.show_navigation ) ? { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev' } : false,
pagination: ( 'yes' === settings.show_pagination ) ? { el: '.my-custom-swiper-pagination.swiper-pagination', clickable: true } : false,
breakpoints: {
640: {
slidesPerView: 1,
spaceBetween: 20,
},
768: {
slidesPerView: 2,
spaceBetween: 40,
},
1024: {
slidesPerView: settings.slides_per_view,
spaceBetween: settings.space_between,
},
},
};
Show full message · 90 lines Assistant2025-06-16 15:29 UTC Copy response
Here's the fully corrected and improved version of your content_template() method, aligned with the PHP render() changes and best practices for live Elementor preview:
applied all these changes. None of the issue were solved.
Assistant2025-06-16 15:34 UTC Copy response
Thanks for applying the changes and reporting back. Since the issues persist, let's do a precise step-by-step debugging and refinement covering the common culprits that typically cause:
Missing live style updates (typography/colors) in Elementor editor.
Partial or missing rendering of portfolio items in Elementor editor preview.
Step 1: Verify proper Control Selectors and Remove Inline Styles
Why?
Elementor’s style controls work by generating CSS based on the selectors you provide in register_controls() via the selectors argument. Inline styles (e.g., in your PHP render() or JS content_template()) override or block Elementor’s CSS injection.
What to do?
Ensure **in your register_controls() all typography and color controls supply correct selectors and remove all inline color/style output from both render() and content_template().
The exact typography and color controls must look like this:
php Copy code
$this->add_control(
'title_color',
[
'label' => esc_html__( 'Title Color', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .my-custom-portfolio-list-item-title' => 'color: {{VALUE}};',
],
]
);
$this->add_group_control(
\Elementor\Group_Control_Typography::get_type(),
[
'name' => 'title_typography',
'label' => esc_html__( 'Title Typography', 'my-custom-portfolio-widget' ),
'selector' => '{{WRAPPER}} .my-custom-portfolio-list-item-title',
]
);
$this->add_control(
'category_color',
[
'label' => esc_html__( 'Category Color', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .my-custom-portfolio-list-item-category' => 'color: {{VALUE}};',
],
]
);
$this->add_group_control(
\Elementor\Group_Control_Typography::get_type(),
[
'name' => 'category_typography',
'label' => esc_html__( 'Category Typography', 'my-custom-portfolio-widget' ),
'selector' => '{{WRAPPER}} .my-custom-portfolio-list-item-category',
]
);
Not yet included in a published release.
plugins_url() vs plugin_dir_url()
You're using plugins_url() with __FILE__ which is perfectly valid and common. For clarity, sometimes plugin_dir_url(__FILE__) is preferred (both resolve URLs to your plugin folder). Not a big issue, just FYI.
5. Missing Uninstall / Deactivation Hooks This is a relatively small widget plugin, so uninstall hooks might not be needed, but if you plan to store options/settings later, you may want to add uninstall cleanup.
6. Security You have if ( ! defined( 'ABSPATH' ) ) { exit; } which is the standard to prevent direct access. Good!
7. Minor Enhancement: Register Widget once Elementor is fully initialized Using plugins_loaded and checking did_action( 'elementor/loaded' ) is good. For complex scenarios, some devs prefer elementor/init or ensuring Elementor's main classes exist via class_exists(). But your current way is fine.
Summary Your main plugin file code looks solid and ready to serve as the foundation for your widget plugin.
Next Steps If you want, please share the portfolio-list-widget.php next so I can review the core widget class. Also, sharing your JS and CSS would help spot if the integration part (Swiper init, styling) is done properly.
Once we confirm the baseline works, we can tackle existing issues or extend features.
Let me know if you want me to point out any specific improvements, or if you'd like me to continue with the next files!
if ( empty( $items ) ) {
return;
}
$swiper_options = [
'slidesPerView' => $settings['slides_per_view'],
'spaceBetween' => $settings['space_between'],
'loop' => ( 'yes' === $settings['loop_carousel'] ),
'autoplay' => ( 'yes' === $settings['autoplay'] ) ? ['delay' => $settings['autoplay_delay']] : false,
'navigation' => ( 'yes' === $settings['show_navigation'] ) ? ['nextEl' => '.swiper-button-next', 'prevEl' => '.swiper-button-prev'] : false,
'pagination' => ( 'yes' === $settings['show_pagination'] ) ? ['el' => '.swiper-pagination', 'clickable' => true] : false,
'breakpoints' => [
640 => ['slidesPerView' => 1, 'spaceBetween' => 20],
768 => ['slidesPerView' => 2, 'spaceBetween' => 40],
1024 => [
'slidesPerView' => $settings['slides_per_view'],
'spaceBetween' => $settings['space_between'],
],
],
];
?>
<div class="my-custom-portfolio-list swiper-container" data-swiper-options='<?php echo json_encode( $swiper_options ); ?>'>
<div class="swiper-wrapper">
<?php foreach ( $items as $item ) :
$link_url = $item['portfolio_item_link']['url'];
$link_target = $item['portfolio_item_link']['is_external'] ? '_blank' : '_self';
$link_nofollow = $item['portfolio_item_link']['nofollow'] ? 'nofollow' : '';
?>
<div class="swiper-slide my-custom-portfolio-list-item">
<div class="my-custom-portfolio-list-item-wrapper">
<?php if ( ! empty( $link_url ) && $link_url !== '#' ) : ?>
<a class="my-custom-portfolio-link" href="<?php echo esc_url( $link_url ); ?>" target="<?php echo esc_attr( $link_target ); ?>" rel="<?php echo esc_attr( $link_nofollow ); ?>"></a>
<?php endif; ?>
<div class="my-custom-portfolio-list-item-media">
<?php if ( 'image' === $item['media_type'] ) : ?>
<?php echo Group_Control_Image_Size::get_attachment_image_html( $item, 'full', 'portfolio_item_image' ); ?>
<?php elseif ( 'self_hosted_video' === $item['media_type'] && ! empty( $item['portfolio_item_video']['url'] ) ) : ?>
<video controls muted playsinline>
<source src="<?php echo esc_url( $item['portfolio_item_video']['url'] ); ?>" type="<?php echo esc_attr( $item['portfolio_item_video']['mime'] ); ?>">
<?php esc_html_e( 'Your browser does not support the video tag.', 'my-custom-portfolio-widget' ); ?>
</video>
<?php elseif ( 'youtube' === $item['media_type'] && ! empty( $item['youtube_video_url']['url'] ) ) :
$youtube_id = preg_match('/(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})/i', $item['youtube_video_url']['url'], $matches) ? $matches[1] : '';
if ( $youtube_id ) : ?>
<div class="my-custom-portfolio-video-embed">
<iframe src="https://www.youtube.com/embed/<?php echo esc_attr( $youtube_id ); ?>?controls=0&showinfo=0&rel=0&autoplay=0&loop=0&mute=1" frameborder="0" allowfullscreen allow="autoplay"></iframe>
</div>
<?php endif; ?>
<?php elseif ( 'vimeo' === $item['media_type'] && ! empty( $item['vimeo_video_url']['url'] ) ) :
$vimeo_id = preg_match('/(?:vimeo\.com\/)(?:channels\/[^\/]+\/|groups\/[^\/]+\/videos\/|album\/\d+\/video\/|video\/|)(\d+)/i', $item['vimeo_video_url']['url'], $matches) ? $matches[1] : '';
if ( $vimeo_id ) : ?>
<div class="my-custom-portfolio-video-embed">
<iframe src="https://player.vimeo.com/video/<?php echo esc_attr( $vimeo_id ); ?>?autoplay=0&loop=0&autopause=0&muted=1" frameborder="0" allowfullscreen allow="autoplay"></iframe>
</div>
<?php endif; ?>
<?php endif; ?>
</div>
<!-- Footer Row with Title, Category, and Pagination (inline) -->
<div class="my-custom-portfolio-list-item-footer">
<div class="my-custom-title"><?php echo esc_html( $item['portfolio_item_title'] ); ?></div>
<div class="my-custom-category"><?php echo esc_html( $item['portfolio_item_category'] ); ?></div>
<?php if ( 'yes' === $settings['show_pagination'] ) : ?>
<div class="my-custom-swiper-pagination swiper-pagination"></div>
<?php endif; ?>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<?php if ( 'yes' === $settings['show_navigation'] ) : ?>
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
<?php endif; ?>
<!-- Removed global pagination (moved into each slide) -->
</div>
<?php
if ( ! settings.portfolio_items || ! settings.portfolio_items.length ) {
return;
}
#>
<div class="my-custom-portfolio-list swiper-container" data-swiper-options='{{ JSON.stringify( swiperOptions ) }}'>
<div class="swiper-wrapper">
<# _.each( settings.portfolio_items, function( item ) {
var media_html = '';
if ( 'image' === item.media_type ) {
var image = {
id: item.portfolio_item_image.id,
url: item.portfolio_item_image.url,
size: item.portfolio_item_image.size,
dimension: item.portfolio_item_image.dimension,
model: item._image,
};
var image_url = elementor.imagesManager.getImageUrl( image );
media_html = '<img src="' + image_url + '" alt="' + item.portfolio_item_title + '">';
} else if ( 'self_hosted_video' === item.media_type && item.portfolio_item_video && item.portfolio_item_video.url ) {
media_html = '<video controls muted playsinline><source src="' + item.portfolio_item_video.url + '" type="' + item.portfolio_item_video.mime + '">Your browser does not support the video tag.</video>';
} else if ( 'youtube' === item.media_type && item.youtube_video_url && item.youtube_video_url.url ) {
var youtube_id = item.youtube_video_url.url.match(/(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})/);
if ( youtube_id && youtube_id[1] ) {
media_html = '<div class="my-custom-portfolio-video-embed"><iframe src="https://www.youtube.com/embed/' + youtube_id[1] + '?controls=0&showinfo=0&rel=0&autoplay=0&loop=0&mute=1" frameborder="0" allowfullscreen allow="autoplay"></iframe></div>';
}
} else if ( 'vimeo' === item.media_type && item.vimeo_video_url && item.vimeo_video_url.url ) {
var vimeo_id = item.vimeo_video_url.url.match(/(?:vimeo\.com\/)(?:channels\/[^\/]+\/|groups\/[^\/]+\/videos\/|album\/\d+\/video\/|video\/|)(\d+)/);
if ( vimeo_id && vimeo_id[1] ) {
media_html = '<div class="my-custom-portfolio-video-embed"><iframe src="https://player.vimeo.com/video/' + vimeo_id[1] + '?autoplay=0&loop=0&autopause=0&muted=1" frameborder="0" allowfullscreen allow="autoplay"></iframe></div>';
}
}
var link_url = item.portfolio_item_link.url;
var link_target = item.portfolio_item_link.is_external ? '_blank' : '_self';
var link_nofollow = item.portfolio_item_link.nofollow ? 'nofollow' : '';
#>
<div class="swiper-slide my-custom-portfolio-list-item">
<a href="{{ link_url }}" target="{{ link_target }}" rel="{{ link_nofollow }}">
<div class="my-custom-portfolio-list-item-media">
{{{ media_html }}}
</div>
<div class="my-custom-portfolio-list-item-info">
<h3 class="my-custom-portfolio-list-item-title">{{{ item.portfolio_item_title }}}</h3>
<p class="my-custom-portfolio-list-item-category">{{{ item.portfolio_item_category }}}</p>
</div>
</a>
</div>
<# } ); #>
</div>
<# if ( 'yes' === settings.show_navigation ) { #>
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
<# } #>
<# if ( 'yes' === settings.show_pagination ) { #>
<div class="my-custom-swiper-pagination swiper-pagination"></div>
<# } #>
</div>
<?php
}
// Helper methods for video IDs
private function get_youtube_id(url) {
preg_match('/(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})/i', url, m a t c h e s ) ; r e t u r n matches);
return ma t c h es ) ; r e t u r n matches[1] ?? '';
}
code Copy code
private function get_vimeo_id($url) {
preg_match('/(?:vimeo\.com\/)(?:channels\/[^\/]+\/|groups\/[^\/]+\/videos\/|album\/\d+\/video\/|video\/|)(\d+)/i', $url, $matches);
return $matches[1] ?? '';
}
<?php
namespace MyCustomPortfolio\Widgets;
use Elementor\Widget_Base;
use Elementor\Controls_Manager;
use Elementor\Repeater;
use Elementor\Group_Control_Image_Size;
use Elementor\Utils;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
class Portfolio_List_Widget extends Widget_Base {
public function get_name() {
return 'portfolio-list-widget';
}
public function get_title() {
return esc_html__( 'My Custom Portfolio List', 'my-custom-portfolio-widget' );
}
public function get_icon() {
return 'eicon-posts-grid';
}
public function get_categories() {
return [ 'general-elements' ];
}
public function get_keywords() {
return [ 'portfolio', 'list', 'carousel', 'swiper', 'image', 'video' ];
}
protected function register_controls() {
// Content Section
$this->start_controls_section(
'section_content',
[
'label' => esc_html__( 'Portfolio List Content', 'my-custom-portfolio-widget' ),
'tab' => Controls_Manager::TAB_CONTENT,
]
);
$repeater = new Repeater();
$repeater->add_control(
'portfolio_item_title',
[
'label' => esc_html__( 'Title', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::TEXT,
'default' => esc_html__( 'Portfolio Item Title', 'my-custom-portfolio-widget' ),
'placeholder' => esc_html__( 'Enter your title', 'my-custom-portfolio-widget' ),
'label_block' => true,
]
);
$repeater->add_control(
'portfolio_item_category',
[
'label' => esc_html__( 'Category', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::TEXT,
'default' => esc_html__( 'Category Name', 'my-custom-portfolio-widget' ),
'placeholder' => esc_html__( 'Enter category', 'my-custom-portfolio-widget' ),
'label_block' => true,
]
);
$repeater->add_control(
'media_type',
[
'label' => esc_html__( 'Media Type', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::SELECT,
'default' => 'image',
'options' => [
'image' => esc_html__( 'Image', 'my-custom-portfolio-widget' ),
'self_hosted_video' => esc_html__( 'Self-Hosted Video', 'my-custom-portfolio-widget' ),
'youtube' => esc_html__( 'YouTube Video', 'my-custom-portfolio-widget' ),
'vimeo' => esc_html__( 'Vimeo Video', 'my-custom-portfolio-widget' ),
],
]
);
$repeater->add_control(
'portfolio_item_image',
[
'label' => esc_html__( 'Image', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::MEDIA,
'default' => [ 'url' => Utils::get_placeholder_image_src() ],
'condition' => [ 'media_type' => 'image' ],
]
);
$repeater->add_control(
'portfolio_item_video',
[
'label' => esc_html__( 'Self-Hosted Video', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::MEDIA,
'media_type' => 'video',
'condition' => [ 'media_type' => 'self_hosted_video' ],
]
);
$repeater->add_control(
'youtube_video_url',
[
'label' => esc_html__( 'YouTube Video URL', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::URL,
'placeholder' => esc_html__( 'http://youtube.com/watch?v=VIDEO_ID', 'my-custom-portfolio-widget' ),
'label_block' => true,
'show_external' => false,
'condition' => [ 'media_type' => 'youtube' ],
]
);
$repeater->add_control(
'vimeo_video_url',
[
'label' => esc_html__( 'Vimeo Video URL', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::URL,
'placeholder' => esc_html__( 'https://vimeo.com/VIDEO_ID', 'my-custom-portfolio-widget' ),
'label_block' => true,
'show_external' => false,
'condition' => [ 'media_type' => 'vimeo' ],
]
);
$repeater->add_control(
'portfolio_item_link',
[
'label' => esc_html__( 'Link', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::URL,
'placeholder' => esc_html__( 'https://your-link.com', 'my-custom-portfolio-widget' ),
'show_external' => true,
'default' => [
'url' => '#',
'is_external' => true,
'nofollow' => true,
],
]
);
$this->add_control(
'portfolio_items',
[
'label' => esc_html__( 'Portfolio Items', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::REPEATER,
'fields' => $repeater->get_controls(),
'default' => [
[
'portfolio_item_title' => esc_html__( 'Portfolio #1', 'my-custom-portfolio-widget' ),
'portfolio_item_category' => esc_html__( 'Design', 'my-custom-portfolio-widget' ),
'media_type' => 'image',
],
[
'portfolio_item_title' => esc_html__( 'Portfolio #2', 'my-custom-portfolio-widget' ),
'portfolio_item_category' => esc_html__( 'Development', 'my-custom-portfolio-widget' ),
'media_type' => 'image',
],
],
'title_field' => '{{{ portfolio_item_title }}}',
]
);
$this->end_controls_section();
// Style Section
$this->start_controls_section(
'section_style',
[
'label' => esc_html__( 'Portfolio List Style', 'my-custom-portfolio-widget' ),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->add_control(
'item_background_color',
[
'label' => esc_html__( 'Item Background Color', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .my-custom-portfolio-list-item' => 'background-color: {{VALUE}};',
],
]
);
$this->add_control(
'media_height',
[
'label' => esc_html__( 'Media Height', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::SLIDER,
'size_units' => [ 'px', 'vh', 'em', '%' ],
'range' => [
'px' => [ 'min' => 0, 'max' => 1000 ],
'vh' => [ 'min' => 0, 'max' => 100 ],
'%' => [ 'min' => 0, 'max' => 100 ],
],
'default' => [ 'unit' => 'vh', 'size' => 80 ],
'selectors' => [
'{{WRAPPER}} .my-custom-portfolio-list-item-media' => 'height: {{SIZE}}{{UNIT}};',
],
]
);
$this->add_control(
'media_object_fit',
[
'label' => esc_html__( 'Media Fit', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::SELECT,
'default' => 'cover',
'options' => [
'fill' => esc_html__( 'Fill', 'my-custom-portfolio-widget' ),
'cover' => esc_html__( 'Cover', 'my-custom-portfolio-widget' ),
'contain' => esc_html__( 'Contain', 'my-custom-portfolio-widget' ),
'none' => esc_html__( 'None', 'my-custom-portfolio-widget' ),
],
'selectors' => [
'{{WRAPPER}} .my-custom-portfolio-list-item-media img, {{WRAPPER}} .my-custom-portfolio-list-item-media video, {{WRAPPER}} .my-custom-portfolio-video-embed iframe' => 'object-fit: {{VALUE}};',
],
]
);
$this->add_control(
'media_object_position',
[
'label' => esc_html__( 'Media Alignment (Object Position)', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::SELECT,
'default' => 'center',
'options' => [
'center' => esc_html__( 'Center', 'my-custom-portfolio-widget' ),
'top' => esc_html__( 'Top', 'my-custom-portfolio-widget' ),
'bottom' => esc_html__( 'Bottom', 'my-custom-portfolio-widget' ),
'left' => esc_html__( 'Left', 'my-custom-portfolio-widget' ),
'right' => esc_html__( 'Right', 'my-custom-portfolio-widget' ),
'top left' => esc_html__( 'Top Left', 'my-custom-portfolio-widget' ),
'top right' => esc_html__( 'Top Right', 'my-custom-portfolio-widget' ),
'bottom left' => esc_html__( 'Bottom Left', 'my-custom-portfolio-widget' ),
'bottom right' => esc_html__( 'Bottom Right', 'my-custom-portfolio-widget' ),
],
'selectors' => [
'{{WRAPPER}} .my-custom-portfolio-list-item-media img, {{WRAPPER}} .my-custom-portfolio-list-item-media video, {{WRAPPER}} .my-custom-portfolio-video-embed iframe' => 'object-position: {{VALUE}};',
],
]
);
$this->add_control(
'text_alignment',
[
'label' => esc_html__( 'Text Alignment', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::CHOOSE,
'options' => [
'flex-start' => [
'title' => esc_html__( 'Left', 'my-custom-portfolio-widget' ),
'icon' => 'eicon-text-align-left',
],
'center' => [
'title' => esc_html__( 'Center', 'my-custom-portfolio-widget' ),
'icon' => 'eicon-text-align-center',
],
'flex-end' => [
'title' => esc_html__( 'Right', 'my-custom-portfolio-widget' ),
'icon' => 'eicon-text-align-right',
],
],
'default' => 'flex-start',
'toggle' => true,
'selectors' => [
'{{WRAPPER}} .my-custom-portfolio-list-item-info' => 'justify-content: {{VALUE}};',
],
]
);
$this->add_control(
'title_color',
[
'label' => esc_html__( 'Title Color', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .my-custom-portfolio-list-item-title' => 'color: {{VALUE}};',
],
]
);
$this->add_group_control(
\Elementor\Group_Control_Typography::get_type(),
[
'name' => 'title_typography',
'label' => esc_html__( 'Title Typography', 'my-custom-portfolio-widget' ),
'selector' => '{{WRAPPER}} .my-custom-portfolio-list-item-title',
]
);
$this->add_control(
'category_color',
[
'label' => esc_html__( 'Category Color', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .my-custom-portfolio-list-item-category' => 'color: {{VALUE}};',
],
]
);
$this->add_group_control(
\Elementor\Group_Control_Typography::get_type(),
[
'name' => 'category_typography',
'label' => esc_html__( 'Category Typography', 'my-custom-portfolio-widget' ),
'selector' => '{{WRAPPER}} .my-custom-portfolio-list-item-category',
]
);
$this->end_controls_section();
// Carousel Settings Section
$this->start_controls_section(
'section_swiper_settings',
[
'label' => esc_html__( 'Carousel Settings', 'my-custom-portfolio-widget' ),
'tab' => Controls_Manager::TAB_CONTENT,
]
);
$this->add_control(
'slides_per_view',
[
'label' => esc_html__( 'Slides Per View', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::NUMBER,
'min' => 1,
'max' => 10,
'step' => 1,
'default' => 3,
]
);
$this->add_control(
'space_between',
[
'label' => esc_html__( 'Space Between Slides', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::NUMBER,
'min' => 0,
'max' => 100,
'step' => 1,
'default' => 30,
]
);
$this->add_control(
'loop_carousel',
[
'label' => esc_html__( 'Loop Carousel', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::SWITCHER,
'label_on' => esc_html__( 'Yes', 'my-custom-portfolio-widget' ),
'label_off' => esc_html__( 'No', 'my-custom-portfolio-widget' ),
'return_value' => 'yes',
'default' => 'no',
]
);
$this->add_control(
'autoplay',
[
'label' => esc_html__( 'Autoplay', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::SWITCHER,
'label_on' => esc_html__( 'Yes', 'my-custom-portfolio-widget' ),
'label_off' => esc_html__( 'No', 'my-custom-portfolio-widget' ),
'return_value' => 'yes',
'default' => 'no',
]
);
$this->add_control(
'autoplay_delay',
[
'label' => esc_html__( 'Autoplay Delay (ms)', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::NUMBER,
'min' => 1000,
'max' => 10000,
'step' => 100,
'default' => 3000,
'condition' => [ 'autoplay' => 'yes' ],
]
);
$this->add_control(
'show_navigation',
[
'label' => esc_html__( 'Navigation Arrows', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::SWITCHER,
'label_on' => esc_html__( 'Show', 'my-custom-portfolio-widget' ),
'label_off' => esc_html__( 'Hide', 'my-custom-portfolio-widget' ),
'return_value' => 'yes',
'default' => 'yes',
]
);
$this->add_control(
'show_pagination',
[
'label' => esc_html__( 'Pagination Dots', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::SWITCHER,
'label_on' => esc_html__( 'Show', 'my-custom-portfolio-widget' ),
'label_off' => esc_html__( 'Hide', 'my-custom-portfolio-widget' ),
'return_value' => 'yes',
'default' => 'yes',
]
);
$this->add_control(
'pagination_bottom_offset',
[
'label' => esc_html__( 'Pagination Dots Offset From Bottom', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::SLIDER,
'size_units' => [ 'px', '%' ],
'range' => [
'px' => [ 'min' => -100, 'max' => 200 ],
'%' => [ 'min' => -50, 'max' => 100 ],
],
'default' => [ 'unit' => 'px', 'size' => 0 ],
'condition' => [ 'show_pagination' => 'yes' ],
'selectors' => [
'{{WRAPPER}} .my-custom-swiper-pagination.swiper-pagination' => 'bottom: {{SIZE}}{{UNIT}};',
],
]
);
$this->end_controls_section();
}
protected function render() {
$settings = $this->get_settings_for_display();
$items = $settings['portfolio_items'];
if ( empty( $items ) ) {
return;
}
$swiper_options = [
'slidesPerView' => $settings['slides_per_view'],
'spaceBetween' => $settings['space_between'],
'loop' => ( 'yes' === $settings['loop_carousel'] ),
'autoplay' => ( 'yes' === $settings['autoplay'] ) ? ['delay' => $settings['autoplay_delay']] : false,
'navigation' => ( 'yes' === $settings['show_navigation'] ) ? ['nextEl' => '.swiper-button-next', 'prevEl' => '.swiper-button-prev'] : false,
'pagination' => ( 'yes' === $settings['show_pagination'] ) ? ['el' => '.swiper-pagination', 'clickable' => true] : false,
'breakpoints' => [
640 => ['slidesPerView' => 1, 'spaceBetween' => 20],
768 => ['slidesPerView' => 2, 'spaceBetween' => 40],
1024 => [
'slidesPerView' => $settings['slides_per_view'],
'spaceBetween' => $settings['space_between'],
],
],
];
?>
<div class="my-custom-portfolio-list swiper-container" data-swiper-options='<?php echo wp_json_encode( $swiper_options ); ?>'>
<div class="swiper-wrapper">
<?php foreach ( $items as $item ) :
$link_url = $item['portfolio_item_link']['url'] ?? '';
$link_target = ! empty($item['portfolio_item_link']['is_external']) ? '_blank' : '_self';
$link_nofollow = ! empty($item['portfolio_item_link']['nofollow']) ? 'nofollow' : '';
?>
<div class="swiper-slide my-custom-portfolio-list-item">
<?php if ( ! empty( $link_url ) && $link_url !== '#' ) : ?>
<a class="my-custom-portfolio-link" href="<?php echo esc_url( $link_url ); ?>" target="<?php echo esc_attr( $link_target ); ?>" rel="<?php echo esc_attr( $link_nofollow ); ?>">
<?php endif; ?>
<div class="my-custom-portfolio-list-item-media">
<?php
switch ( $item['media_type'] ) {
case 'image':
echo Group_Control_Image_Size::get_attachment_image_html( $item, 'full', 'portfolio_item_image' );
break;
case 'self_hosted_video':
if ( ! empty( $item['portfolio_item_video']['url'] ) ) : ?>
<video controls muted playsinline>
<source src="<?php echo esc_url( $item['portfolio_item_video']['url'] ); ?>" type="<?php echo esc_attr( $item['portfolio_item_video']['mime'] ); ?>">
<?php esc_html_e( 'Your browser does not support the video tag.', 'my-custom-portfolio-widget' ); ?>
</video>
<?php endif;
break;
case 'youtube':
$youtube_id = $this->get_youtube_id( $item['youtube_video_url']['url'] ?? '' );
if ( $youtube_id ) : ?>
<div class="my-custom-portfolio-video-embed">
<iframe src="https://www.youtube.com/embed/<?php echo esc_attr( $youtube_id ); ?>?controls=0&showinfo=0&rel=0&autoplay=0&loop=0&mute=1" frameborder="0" allowfullscreen allow="autoplay"></iframe>
</div>
<?php endif;
break;
case 'vimeo':
$vimeo_id = $this->get_vimeo_id( $item['vimeo_video_url']['url'] ?? '' );
if ( $vimeo_id ) : ?>
<div class="my-custom-portfolio-video-embed">
<iframe src="https://player.vimeo.com/video/<?php echo esc_attr( $vimeo_id ); ?>?autoplay=0&loop=0&autopause=0&muted=1" frameborder="0" allowfullscreen allow="autoplay"></iframe>
</div>
<?php endif;
break;
}
?>
</div>
<?php if ( ! empty( $link_url ) && $link_url !== '#' ) : ?>
</a>
<?php endif; ?>
<div class="my-custom-portfolio-list-item-info" style="justify-content: <?php echo esc_attr( $settings['text_alignment'] ); ?>;">
<h3 class="my-custom-portfolio-list-item-title" style="color: <?php echo esc_attr( $settings['title_color'] ); ?>; <?php echo $this->get_inline_typography_css( $settings, 'title_typography' ); ?>">
<?php echo esc_html( $item['portfolio_item_title'] ); ?>
</h3>
<p class="my-custom-portfolio-list-item-category" style="color: <?php echo esc_attr( $settings['category_color'] ); ?>; <?php echo $this->get_inline_typography_css( $settings, 'category_typography' ); ?>">
<?php echo esc_html( $item['portfolio_item_category'] ); ?>
</p>
</div>
</div>
<?php endforeach; ?>
</div>
<?php if ( 'yes' === $settings['show_navigation'] ) : ?>
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
<?php endif; ?>
<?php if ( 'yes' === $settings['show_pagination'] ) : ?>
<div class="my-custom-swiper-pagination swiper-pagination"></div>
<?php endif; ?>
</div>
<?php
}
protected function content_template() {
?>
<#
var settings = settings;
var swiperOptions = {
slidesPerView: settings.slides_per_view,
spaceBetween: settings.space_between,
loop: ( 'yes' === settings.loop_carousel ),
autoplay: ( 'yes' === settings.autoplay ) ? { delay: settings.autoplay_delay } : false,
navigation: ( 'yes' === settings.show_navigation ) ? { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev' } : false,
pagination: ( 'yes' === settings.show_pagination ) ? { el: '.my-custom-swiper-pagination.swiper-pagination', clickable: true } : false,
breakpoints: {
640: {
slidesPerView: 1,
spaceBetween: 20,
},
768: {
slidesPerView: 2,
spaceBetween: 40,
},
1024: {
slidesPerView: settings.slides_per_view,
spaceBetween: settings.space_between,
},
},
};
if ( ! settings.portfolio_items || ! settings.portfolio_items.length ) {
return;
}
#>
<div class="my-custom-portfolio-list swiper-container" data-swiper-options='{{ JSON.stringify( swiperOptions ) }}'>
<div class="swiper-wrapper">
<# _.each( settings.portfolio_items, function( item ) {
var media_html = '';
if ( 'image' === item.media_type ) {
var image = {
id: item.portfolio_item_image.id,
url: item.portfolio_item_image.url,
size: item.portfolio_item_image.size,
dimension: item.portfolio_item_image.dimension,
model: item._image,
};
var image_url = elementor.imagesManager.getImageUrl( image );
media_html = '<img src="' + image_url + '" alt="' + item.portfolio_item_title + '">';
} else if ( 'self_hosted_video' === item.media_type && item.portfolio_item_video && item.portfolio_item_video.url ) {
media_html = '<video controls muted playsinline><source src="' + item.portfolio_item_video.url + '" type="' + item.portfolio_item_video.mime + '">Your browser does not support the video tag.</video>';
} else if ( 'youtube' === item.media_type && item.youtube_video_url && item.youtube_video_url.url ) {
var youtube_id = item.youtube_video_url.url.match(/(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})/);
if ( youtube_id && youtube_id[1] ) {
media_html = '<div class="my-custom-portfolio-video-embed"><iframe src="https://www.youtube.com/embed/' + youtube_id[1] + '?controls=0&showinfo=0&rel=0&autoplay=0&loop=0&mute=1" frameborder="0" allowfullscreen allow="autoplay"></iframe></div>';
}
} else if ( 'vimeo' === item.media_type && item.vimeo_video_url && item.vimeo_video_url.url ) {
var vimeo_id = item.vimeo_video_url.url.match(/(?:vimeo\.com\/)(?:channels\/[^\/]+\/|groups\/[^\/]+\/videos\/|album\/\d+\/video\/|video\/|)(\d+)/);
if ( vimeo_id && vimeo_id[1] ) {
media_html = '<div class="my-custom-portfolio-video-embed"><iframe src="https://player.vimeo.com/video/' + vimeo_id[1] + '?autoplay=0&loop=0&autopause=0&muted=1" frameborder="0" allowfullscreen allow="autoplay"></iframe></div>';
}
}
var link_url = item.portfolio_item_link.url;
var link_target = item.portfolio_item_link.is_external ? '_blank' : '_self';
var link_nofollow = item.portfolio_item_link.nofollow ? 'nofollow' : '';
#>
<div class="swiper-slide my-custom-portfolio-list-item">
<a href="{{ link_url }}" target="{{ link_target }}" rel="{{ link_nofollow }}">
<div class="my-custom-portfolio-list-item-media">
{{{ media_html }}}
</div>
<div class="my-custom-portfolio-list-item-info">
<h3 class="my-custom-portfolio-list-item-title">{{{ item.portfolio_item_title }}}</h3>
<p class="my-custom-portfolio-list-item-category">{{{ item.portfolio_item_category }}}</p>
</div>
</a>
</div>
<# } ); #>
</div>
<# if ( 'yes' === settings.show_navigation ) { #>
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
<# } #>
<# if ( 'yes' === settings.show_pagination ) { #>
<div class="my-custom-swiper-pagination swiper-pagination"></div>
<# } #>
</div>
<?php
}
private function get_youtube_id( $url ) {
preg_match( '/(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})/i', $url, $matches );
return $matches[1] ?? '';
}
private function get_vimeo_id( $url ) {
preg_match( '/(?:vimeo\.com\/)(?:channels\/[^\/]+\/|groups\/[^\/]+\/videos\/|album\/\d+\/video\/|video\/|)(\d+)/i', $url, $matches );
return $matches[1] ?? '';
}
/**
* Helper to generate inline CSS for typography settings.
*
* @param array $settings Widget settings.
* @param string $control_name Typography control name.
* @return string
*/
private function get_inline_typography_css( $settings, $control_name ) {
if ( empty( $settings[ $control_name ] ) || ! is_array( $settings[ $control_name ] ) ) {
return '';
}
$css = '';
$typo = $settings[ $control_name ];
if ( ! empty( $typo['font_family'] ) ) {
$css .= 'font-family:' . esc_attr( $typo['font_family'] ) . ';';
}
if ( ! empty( $typo['font_size'] ) ) {
$css .= 'font-size:' . esc_attr( $typo['font_size'] ) . ';';
}
if ( ! empty( $typo['font_style'] ) ) {
$css .= 'font-style:' . esc_attr( $typo['font_style'] ) . ';';
}
if ( ! empty( $typo['font_weight'] ) ) {
$css .= 'font-weight:' . esc_attr( $typo['font_weight'] ) . ';';
}
if ( ! empty( $typo['letter_spacing'] ) ) {
$css .= 'letter-spacing:' . esc_attr( $typo['letter_spacing'] ) . ';';
}
if ( ! empty( $typo['text_decoration'] ) ) {
$css .= 'text-decoration:' . esc_attr( $typo['text_decoration'] ) . ';';
}
if ( ! empty( $typo['line_height'] ) ) {
$css .= 'line-height:' . esc_attr( $typo['line_height'] ) . ';';
}
if ( ! empty( $typo['text_transform'] ) ) {
$css .= 'text-transform:' . esc_attr( $typo['text_transform'] ) . ';';
}
return $css;
}
}
Key Improvements & Notes
Consistent HTML structure between render PHP and JS template.
Wrapped clickable area properly — media and info inside the link if link specified.
Used wp_json_encode() instead of json_encode() for safety.
Added null coalescing operators (??) to avoid undefined index notices.
Extracted video ID regex into private methods to avoid repeating.
Added helper method get_inline_typography_css() to apply typography inline styles cleanly.
Escape all outputs with proper escaping functions.
Fixed pagination markup: only one global .swiper-pagination container instead of inside each slide footer.
Simplified autoplay, navigation, and pagination options with boolean or config objects.
Used switch-case in PHP render media block instead of multiple if-elseif for clarity.
Removed redundant inline style for text alignment from control selectors and handled in PHP render only.
The content_template() aligns with the PHP output format in structure.
Minor formatting and comment cleanup.
This should be a solid, clean, and consistent starting point for your widget's core PHP class.
Please let me know when you are ready to share the next file or if you want to proceed with this updated widget class as basis!
/* Responsive adjustments if needed */
@media screen and (max-width: 767px) {
.my-custom-portfolio-list-item-footer {
flex-direction: column;
align-items: flex-start;
gap: 8px;
}
code Copy code
.my-custom-swiper-pagination.swiper-pagination {
justify-content: flex-start;
margin-left: 0;
padding-left: 0;
}
/* === General Widget Container === */
.elementor-widget-my-custom-portfolio-list {
position: relative;
width: 100%;
overflow: hidden;
}
/* === Swiper Container and Slides === */
.my-custom-portfolio-list {
width: 100%;
overflow: hidden;
}
.swiper-slide {
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-start;
padding-bottom: 50px;
width: 100%;
flex-shrink: 0;
box-sizing: border-box;
}
/* === Portfolio Item Structure === */
.my-custom-portfolio-list-item {
width: 100%;
display: flex;
flex-direction: column;
align-items: flex-start;
position: relative;
box-sizing: border-box;
}
.my-custom-portfolio-list-item-wrapper {
position: relative;
display: block;
width: 100%;
height: 100%;
}
/* === Displayed Image or Video === */
.my-custom-portfolio-list-item-media {
width: 100%;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
}
.my-custom-portfolio-list-item-media img,
.my-custom-portfolio-list-item-media video {
width: 100%;
height: 100%;
display: block;
}
.my-custom-portfolio-video-embed {
position: relative;
width: 100%;
/* Maintain 16:9 aspect ratio */
padding-bottom: 56.25%;
height: 0;
overflow: hidden;
min-height: 150px; /* fallback height */
}
.my-custom-portfolio-video-embed iframe,
.my-custom-portfolio-video-embed object,
.my-custom-portfolio-video-embed embed {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
/* === Footer with Title, Category, and Pagination Inline === */
.my-custom-portfolio-list-item-footer {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
padding-top: 10px;
gap: 20px;
}
.my-custom-title {
flex: 1;
font-weight: bold;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
text-align: left;
}
.my-custom-category {
flex: 2;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
text-align: left;
}
/* === Inline Pagination Bullets === */
.my-custom-swiper-pagination.swiper-pagination {
position: relative !important;
width: auto;
display: flex;
align-items: center;
justify-content: flex-end;
margin-left: auto;
padding-left: 10px;
gap: 4px;
}
/* Pagination bullet styling */
.swiper-pagination-bullet {
background-color: transparent !important;
border: none !important;
opacity: 1 !important;
outline: none;
}
.my-custom-swiper-pagination .swiper-pagination-bullet {
background: #ccc;
opacity: 1;
margin: 0 5px;
position: relative;
width: 1.1rem;
height: 0.65rem;
border-radius: 999px;
transition: width 0.3s, background-color 0.3s;
}
.my-custom-swiper-pagination .swiper-pagination-bullet-active {
background: #000;
width: 1.1rem;
}
.my-custom-swiper-pagination .swiper-pagination-bullet:focus {
outline: none;
}
/* === Link Overlay Cover === */
.my-custom-portfolio-link {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 5;
opacity: 0;
}
/* Ensure media and footer remain clickable */
.my-custom-portfolio-list-item-media,
.my-custom-portfolio-list-item-footer {
position: relative;
z-index: 1;
}
/* === Responsive adjustments === */
@media screen and (max-width: 767px) {
.my-custom-portfolio-list-item-footer {
flex-direction: column;
align-items: flex-start;
gap: 8px;
}
.my-custom-swiper-pagination.swiper-pagination {
justify-content: flex-start;
margin-left: 0;
padding-left: 0;
}
}
Let me know when you want to move on with the next file (portfolio-list.js), or if you'd like me to proceed with any adjustments or troubleshooting next!
(function ($) {
'use strict';
// Debug flag - set to false for production to disable console logs
var DEBUG = false;
if (DEBUG) {
console.log('portfolio-list.js STARTING EXECUTION!');
console.log('portfolio-list.js is running!');
}
var initPortfolioSwipers = function () {
var swiperContainers = $('.my-custom-portfolio-list.swiper-container');
if (swiperContainers.length) {
swiperContainers.each(function () {
var $this = $(this);
var swiperOptions = $this.data('swiper-options') || {};
if (swiperOptions.navigation && typeof swiperOptions.navigation === 'object') {
var nextEl = $this.find('.swiper-button-next')[0];
var prevEl = $this.find('.swiper-button-prev')[0];
if (nextEl && prevEl) {
swiperOptions.navigation.nextEl = nextEl;
swiperOptions.navigation.prevEl = prevEl;
}
}
if (swiperOptions.pagination && typeof swiperOptions.pagination === 'object') {
var paginationEl = $this.find('.swiper-pagination')[0];
if (paginationEl) {
swiperOptions.pagination.el = paginationEl;
}
}
if (typeof Swiper !== 'undefined') {
new Swiper($this[0], swiperOptions);
if (DEBUG) {
console.log('Swiper initialized on:', $this[0]);
}
} else {
if (DEBUG) {
console.warn('Swiper library not found. Please ensure it is enqueued.');
}
}
});
}
};
// Initialize on document ready (front-end page load)
$(document).ready(function () {
initPortfolioSwipers();
});
// Initialize for Elementor editor & frontend widget rendering
$(window).on('elementor/frontend/init', function () {
elementorFrontend.hooks.addAction('frontend/element_ready/portfolio-list-widget.default', initPortfolioSwipers);
});
})(jQuery);
Summary
This final version tracks everything your original script did but adds a debug flag for easy disabling of logs.
Clear jQuery caching and safer checks.
Simple and effective Swiper initialization compatible with Elementor best practices.
Let me know if you want me to assist next with wiring this all together, further improvements, or start debugging your reported issues!
<?php
/**
* Plugin Name: My Custom Portfolio List Widget
* Description: A custom Elementor widget for displaying portfolio items in a Swiper carousel.
* Version: 1.0.0
* Author: 0danye0
* Elementor tested up to: 3.29.2
* Elementor Pro tested up to: 3.29.2
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Main Plugin Class for My Custom Portfolio Widget.
*/
final class My_Custom_Portfolio_Widget_Plugin {
/**
* Plugin Version.
*
* @since 1.0.0
* @var string The plugin version.
*/
const VERSION = '1.0.0';
/**
* Minimum Elementor Version.
*
* @since 1.0.0
* @var string Minimum Elementor version required.
*/
const MINIMUM_ELEMENTOR_VERSION = '3.0.0';
/**
* Minimum PHP Version.
*
* @since 1.0.0
* @var string Minimum PHP version required.
*/
const MINIMUM_PHP_VERSION = '7.4';
/**
* Constructor.
*
* @since 1.0.0
* @access public
*/
public function __construct() {
add_action( 'plugins_loaded', [ $this, 'on_plugins_loaded' ] );
}
/**
* Called when all plugins are loaded.
*
* @since 1.0.0
* @access public
*/
public function on_plugins_loaded() {
if ( ! did_action( 'elementor/loaded' ) ) {
add_action( 'admin_notices', [ $this, 'admin_notice_missing_elementor' ] );
return;
}
if ( ! version_compare( ELEMENTOR_VERSION, self::MINIMUM_ELEMENTOR_VERSION, '>=' ) ) {
add_action( 'admin_notices', [ $this, 'admin_notice_minimum_elementor_version' ] );
return;
}
if ( version_compare( PHP_VERSION, self::MINIMUM_PHP_VERSION, '<' ) ) {
add_action( 'admin_notices', [ $this, 'admin_notice_minimum_php_version' ] );
return;
}
add_action( 'elementor/widgets/register', [ $this, 'register_widgets' ] );
add_action( 'elementor/frontend/after_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
}
/**
* Register Elementor Widgets.
*
* @since 1.0.0
* @access public
* @param \Elementor\Widgets_Manager $widgets_manager Elementor widgets manager.
*/
public function register_widgets( $widgets_manager ) {
require_once __DIR__ . '/widgets/portfolio-list-widget.php';
$widgets_manager->register( new \MyCustomPortfolio\Widgets\Portfolio_List_Widget() );
}
/**
* Enqueue scripts and styles.
*
* @since 1.0.0
* @access public
*/
public function enqueue_scripts() {
if ( ! defined( 'ELEMENTOR_VERSION' ) ) {
return;
}
// Enqueue Swiper JS and CSS from our plugin's assets/libs/swiper folder
wp_enqueue_script(
'swiper-js',
plugins_url( 'assets/libs/swiper/swiper-bundle.min.js', __FILE__ ),
[],
filemtime( plugin_dir_path( __FILE__ ) . 'assets/libs/swiper/swiper-bundle.min.js' ),
true
);
wp_enqueue_style(
'swiper-css',
plugins_url( 'assets/libs/swiper/swiper-bundle.min.css', __FILE__ ),
[],
filemtime( plugin_dir_path( __FILE__ ) . 'assets/libs/swiper/swiper-bundle.min.css' )
);
// Enqueue our custom script and style
wp_enqueue_script(
'my-custom-portfolio-list-script',
plugins_url( 'assets/js/portfolio-list.js', __FILE__ ),
[ 'jquery', 'swiper-js' ],
filemtime( plugin_dir_path( __FILE__ ) . 'assets/js/portfolio-list.js' ),
true
);
wp_enqueue_style(
'my-custom-portfolio-list-style',
plugins_url( 'assets/css/portfolio-list.css', __FILE__ ),
[],
filemtime( plugin_dir_path( __FILE__ ) . 'assets/css/portfolio-list.css' )
);
}
/**
* Admin notice for missing Elementor plugin.
*/
public function admin_notice_missing_elementor() {
if ( isset( $_GET['activate'] ) ) {
unset( $_GET['activate'] );
}
$message = sprintf(
esc_html__( '"%1$s" requires "%2$s" to be installed and activated.', 'my-custom-portfolio-widget' ),
'<strong>' . esc_html__( 'My Custom Portfolio List Widget', 'my-custom-portfolio-widget' ) . '</strong>',
'<strong>' . esc_html__( 'Elementor', 'my-custom-portfolio-widget' ) . '</strong>'
);
printf( '<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', $message );
}
/**
* Admin notice for minimum Elementor version not met.
*/
public function admin_notice_minimum_elementor_version() {
if ( isset( $_GET['activate'] ) ) {
unset( $_GET['activate'] );
}
$message = sprintf(
esc_html__( '"%1$s" requires "%2$s" version %3$s or greater.', 'my-custom-portfolio-widget' ),
'<strong>' . esc_html__( 'My Custom Portfolio List Widget', 'my-custom-portfolio-widget' ) . '</strong>',
'<strong>' . esc_html__( 'Elementor', 'my-custom-portfolio-widget' ) . '</strong>',
self::MINIMUM_ELEMENTOR_VERSION
);
printf( '<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', $message );
}
/**
* Admin notice for minimum PHP version not met.
*/
public function admin_notice_minimum_php_version() {
if ( isset( $_GET['activate'] ) ) {
unset( $_GET['activate'] );
}
$message = sprintf(
esc_html__( '"%1$s" requires PHP version %2$s or greater.', 'my-custom-portfolio-widget' ),
'<strong>' . esc_html__( 'My Custom Portfolio List Widget', 'my-custom-portfolio-widget' ) . '</strong>',
'<strong>' . esc_html__( 'PHP', 'my-custom-portfolio-widget' ) . '</strong>',
self::MINIMUM_PHP_VERSION
);
printf( '<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', $message );
}
}
new My_Custom_Portfolio_Widget_Plugin();
Notes:
Removed error_log() debug lines for production cleanliness.
Added a safety check in enqueue_scripts to ensure ELEMENTOR_VERSION is defined before enqueueing.
Used __DIR__ and plugin_dir_path consistently.
Cleaned spacing and PHPDoc comments for clarity.
Kept the admin notices as is — they’re working properly.
Class is final and properly instantiated at the end.
Let me know if you want me to help with anything else!
Replace the corresponding CSS block for .my-custom-portfolio-list-item-footer and its children with this code:
css Copy code
.my-custom-portfolio-list-item-footer {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
padding-top: 10px;
gap: 10px; /* reduced spacing */
}
/* Title on left */
.my-custom-title {
/* flex handled inline */
text-align: left;
font-weight: bold;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
/* Category center, about 65% width */
.my-custom-category {
flex: 0 0 65%;
text-align: center;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
/* Pagination dots align right */
.my-custom-swiper-pagination.swiper-pagination {
flex: 0 0 auto;
display: flex;
justify-content: flex-end;
margin-left: auto;
padding-left: 0;
}
IMPORTANT NOTES
Pagination dots must be rendered only once per slider , not repeated for every slide.
So the code above assumes pagination dots are placed OUTSIDE the slides (as footer of whole slider). If your pagination dots are rendered inside each slide , that causes the pagination dots appearing multiple times.
The code I gave uses a single pagination wrapper in the footer container.
If your widget already renders pagination dots globally (outside loop of slides), just move the <div class="my-custom-swiper-pagination swiper-pagination"></div> into the footer container as shown above.
Otherwise, move it out of slides and place it immediately below .swiper-wrapper.
Optional: You can also replace the entire footer section in the render method loop for clarity, here is a more complete snippet example Full snippet for the footer inside your render loop:
php Copy code
<div class="my-custom-portfolio-list-item-footer">
<div class="my-custom-title" style="flex: 1; text-align: left; color: <?php echo esc_attr( $settings['title_color'] ); ?>;">
<?php echo esc_html( $item['portfolio_item_title'] ); ?>
</div>
<div class="my-custom-category" style="flex: 0 0 65%; text-align: center; color: <?php echo esc_attr( $settings['category_color'] ); ?>;">
<?php echo esc_html( $item['portfolio_item_category'] ); ?>
</div>
<?php if ( 'yes' === $settings['show_pagination'] ) : ?>
<div class="my-custom-swiper-pagination swiper-pagination" style="flex: 0 0 auto; text-align: right;"></div>
<?php endif; ?>
</div>
Summary
Modify the footer markup as shown in Step 1 (inside PHP render loop).
Update CSS styles for that footer container and children as shown in Step 2 (portfolio-list.css).
Make sure that pagination dots appear only once per slider — inside footer container but outside slides .
Please update those two files by replacing the indicated sections, then refresh cache / browser.
If you want me to post the full updated render() method or CSS file snippet together so you can copy/paste straightforwardly, just say so!
2) assets/css/portfolio-list.css
What to replace? Replace the CSS block starting with:
css Copy code
.my-custom-portfolio-list-item-footer {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
padding-top: 10px;
gap: 20px;
}
.my-custom-title {
flex: 1;
font-weight: bold;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
text-align: left;
}
.my-custom-category {
flex: 2;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
text-align: left;
}
/* ... pagination styles */
Replace it entirely with this updated CSS: css Copy code
.my-custom-portfolio-list-item-footer {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
padding-top: 10px;
gap: 10px; /* reduced gap */
}
/* Title on the left */
.my-custom-title {
text-align: left;
font-weight: bold;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
/* Category centered and about 65% width */
.my-custom-category {
flex: 0 0 65%;
text-align: center;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
/* Pagination dots aligned right */
.my-custom-swiper-pagination.swiper-pagination {
flex: 0 0 auto;
display: flex;
justify-content: flex-end;
margin-left: auto;
padding-left: 0;
}
Important notes:
Make sure the pagination dots <div class="my-custom-swiper-pagination swiper-pagination"></div> only appear once per slider — it must be inside the same footer container outside the slides loop .
If you currently have pagination dots inside every slide, remove them from individual slides and place one outside .swiper-wrapper but inside .my-custom-portfolio-list , ideally below .swiper-wrapper and within the same footer container.
Your footer code now has inline styles for colors and typography — these were added from your existing control setup to keep consistent formatting.
Summary File What to replace What to insert widgets/portfolio-list-widget.phpReplace footer div inside each slide’s loop The new footer div with flex: 1, flex: 0 0 65% and pagination flex styles and inline style for colors & typography assets/css/portfolio-list.cssReplace .my-custom-portfolio-list-item-footer and related styles The updated footer CSS with reduced gap, correct flex widths, and alignment
If you want, I can also help you move the pagination outside the loop in your PHP and show you exactly how to do that for full correctness. Just tell me!
if ( empty( $items ) ) {
return;
}
$swiper_options = [
'slidesPerView' => $settings['slides_per_view'],
'spaceBetween' => $settings['space_between'],
'loop' => ( 'yes' === $settings['loop_carousel'] ),
'autoplay' => ( 'yes' === $settings['autoplay'] ) ? ['delay' => $settings['autoplay_delay']] : false,
'navigation' => ( 'yes' === $settings['show_navigation'] ) ? ['nextEl' => '.swiper-button-next', 'prevEl' => '.swiper-button-prev'] : false,
'pagination' => ( 'yes' === $settings['show_pagination'] ) ? ['el' => '.swiper-pagination', 'clickable' => true] : false,
'breakpoints' => [
640 => ['slidesPerView' => 1, 'spaceBetween' => 20],
768 => ['slidesPerView' => 2, 'spaceBetween' => 40],
1024 => [
'slidesPerView' => $settings['slides_per_view'],
'spaceBetween' => $settings['space_between'],
],
],
];
?>
<div class="my-custom-portfolio-list swiper-container" data-swiper-options='<?php echo wp_json_encode( $swiper_options ); ?>'>
<div class="swiper-wrapper">
<?php foreach ( $items as $item ) :
$link_url = $item['portfolio_item_link']['url'] ?? '';
$link_target = ! empty($item['portfolio_item_link']['is_external']) ? '_blank' : '_self';
$link_nofollow = ! empty($item['portfolio_item_link']['nofollow']) ? 'nofollow' : '';
?>
<div class="swiper-slide my-custom-portfolio-list-item">
<?php if ( ! empty( $link_url ) && $link_url !== '#' ) : ?>
<a class="my-custom-portfolio-link" href="<?php echo esc_url( $link_url ); ?>" target="<?php echo esc_attr( $link_target ); ?>" rel="<?php echo esc_attr( $link_nofollow ); ?>">
<?php endif; ?>
<div class="my-custom-portfolio-list-item-media">
<?php
switch ( $item['media_type'] ) {
case 'image':
echo Group_Control_Image_Size::get_attachment_image_html( $item, 'full', 'portfolio_item_image' );
break;
case 'self_hosted_video':
if ( ! empty( $item['portfolio_item_video']['url'] ) ) : ?>
<video controls muted playsinline>
<source src="<?php echo esc_url( $item['portfolio_item_video']['url'] ); ?>" type="<?php echo esc_attr( $item['portfolio_item_video']['mime'] ); ?>">
<?php esc_html_e( 'Your browser does not support the video tag.', 'my-custom-portfolio-widget' ); ?>
</video>
<?php endif;
break;
case 'youtube':
$youtube_id = $this->get_youtube_id( $item['youtube_video_url']['url'] ?? '' );
if ( $youtube_id ) : ?>
<div class="my-custom-portfolio-video-embed">
<iframe src="https://www.youtube.com/embed/<?php echo esc_attr( $youtube_id ); ?>?controls=0&showinfo=0&rel=0&autoplay=0&loop=0&mute=1" frameborder="0" allowfullscreen allow="autoplay"></iframe>
</div>
<?php endif;
break;
case 'vimeo':
$vimeo_id = $this->get_vimeo_id( $item['vimeo_video_url']['url'] ?? '' );
if ( $vimeo_id ) : ?>
<div class="my-custom-portfolio-video-embed">
<iframe src="https://player.vimeo.com/video/<?php echo esc_attr( $vimeo_id ); ?>?autoplay=0&loop=0&autopause=0&muted=1" frameborder="0" allowfullscreen allow="autoplay"></iframe>
</div>
<?php endif;
break;
}
?>
</div>
<?php if ( ! empty( $link_url ) && $link_url !== '#' ) : ?>
</a>
<?php endif; ?>
<div class="my-custom-portfolio-list-item-info" style="justify-content: <?php echo esc_attr( $settings['text_alignment'] ); ?>;">
<h3 class="my-custom-portfolio-list-item-title" style="color: <?php echo esc_attr( $settings['title_color'] ); ?>; <?php echo $this->get_inline_typography_css( $settings, 'title_typography' ); ?>">
<?php echo esc_html( $item['portfolio_item_title'] ); ?>
</h3>
<p class="my-custom-portfolio-list-item-category" style="color: <?php echo esc_attr( $settings['category_color'] ); ?>; <?php echo $this->get_inline_typography_css( $settings, 'category_typography' ); ?>">
<?php echo esc_html( $item['portfolio_item_category'] ); ?>
</p>
</div>
</div>
<?php endforeach; ?>
</div>
<?php if ( 'yes' === $settings['show_navigation'] ) : ?>
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
<?php endif; ?>
<?php if ( 'yes' === $settings['show_pagination'] ) : ?>
<div class="my-custom-swiper-pagination swiper-pagination"></div>
<?php endif; ?>
</div>
<?php
}
protected function render() {
$settings = $this->get_settings_for_display();
$items = $settings['portfolio_items'];
if ( empty( $items ) ) {
return;
}
$swiper_options = [
'slidesPerView' => $settings['slides_per_view'],
'spaceBetween' => $settings['space_between'],
'loop' => ( 'yes' === $settings['loop_carousel'] ),
'autoplay' => ( 'yes' === $settings['autoplay'] ) ? ['delay' => $settings['autoplay_delay']] : false,
'navigation' => ( 'yes' === $settings['show_navigation'] ) ? ['nextEl' => '.swiper-button-next', 'prevEl' => '.swiper-button-prev'] : false,
'pagination' => ( 'yes' === $settings['show_pagination'] ) ? ['el' => '.swiper-pagination', 'clickable' => true] : false,
'breakpoints' => [
640 => ['slidesPerView' => 1, 'spaceBetween' => 20],
768 => ['slidesPerView' => 2, 'spaceBetween' => 40],
1024 => [
'slidesPerView' => $settings['slides_per_view'],
'spaceBetween' => $settings['space_between'],
],
],
];
?>
<div class="my-custom-portfolio-list swiper-container" data-swiper-options='<?php echo wp_json_encode( $swiper_options ); ?>'>
<div class="swiper-wrapper">
<?php foreach ( $items as $item ) :
$link_url = $item['portfolio_item_link']['url'] ?? '';
$link_target = ! empty( $item['portfolio_item_link']['is_external'] ) ? '_blank' : '_self';
$link_nofollow = ! empty( $item['portfolio_item_link']['nofollow'] ) ? 'nofollow' : '';
?>
<div class="swiper-slide my-custom-portfolio-list-item">
<?php if ( ! empty( $link_url ) && $link_url !== '#' ) : ?>
<a class="my-custom-portfolio-link" href="<?php echo esc_url( $link_url ); ?>" target="<?php echo esc_attr( $link_target ); ?>" rel="<?php echo esc_attr( $link_nofollow ); ?>">
<?php endif; ?>
<div class="my-custom-portfolio-list-item-media">
<?php
switch ( $item['media_type'] ) {
case 'image':
echo Group_Control_Image_Size::get_attachment_image_html( $item, 'full', 'portfolio_item_image' );
break;
case 'self_hosted_video':
if ( ! empty( $item['portfolio_item_video']['url'] ) ) : ?>
<video controls muted playsinline>
<source src="<?php echo esc_url( $item['portfolio_item_video']['url'] ); ?>" type="<?php echo esc_attr( $item['portfolio_item_video']['mime'] ); ?>">
<?php esc_html_e( 'Your browser does not support the video tag.', 'my-custom-portfolio-widget' ); ?>
</video>
<?php endif;
break;
case 'youtube':
$youtube_id = $this->get_youtube_id( $item['youtube_video_url']['url'] ?? '' );
if ( $youtube_id ) : ?>
<div class="my-custom-portfolio-video-embed">
<iframe src="https://www.youtube.com/embed/<?php echo esc_attr( $youtube_id ); ?>?controls=0&showinfo=0&rel=0&autoplay=0&loop=0&mute=1" frameborder="0" allowfullscreen allow="autoplay"></iframe>
</div>
<?php endif;
break;
case 'vimeo':
$vimeo_id = $this->get_vimeo_id( $item['vimeo_video_url']['url'] ?? '' );
if ( $vimeo_id ) : ?>
<div class="my-custom-portfolio-video-embed">
<iframe src="https://player.vimeo.com/video/<?php echo esc_attr( $vimeo_id ); ?>?autoplay=0&loop=0&autopause=0&muted=1" frameborder="0" allowfullscreen allow="autoplay"></iframe>
</div>
<?php endif;
break;
}
?>
</div>
<?php if ( ! empty( $link_url ) && $link_url !== '#' ) : ?>
</a>
<?php endif; ?>
<div class="my-custom-portfolio-list-item-footer" style="display: flex; align-items: center; justify-content: space-between; width: 100%; padding-top: 10px; gap: 10px;">
<div class="my-custom-title" style="flex: 1; text-align: left; color: <?php echo esc_attr( $settings['title_color'] ); ?>; <?php echo $this->get_inline_typography_css( $settings, 'title_typography' ); ?>">
<?php echo esc_html( $item['portfolio_item_title'] ); ?>
</div>
<div class="my-custom-category" style="flex: 0 0 65%; text-align: center; color: <?php echo esc_attr( $settings['category_color'] ); ?>; <?php echo $this->get_inline_typography_css( $settings, 'category_typography' ); ?>">
<?php echo esc_html( $item['portfolio_item_category'] ); ?>
</div>
<!-- NOTE: No pagination dots here -->
</div>
</div>
<?php endforeach; ?>
</div>
<?php if ( 'yes' === $settings['show_navigation'] ) : ?>
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
<?php endif; ?>
<?php if ( 'yes' === $settings['show_pagination'] ) : ?>
<div class="my-custom-swiper-pagination swiper-pagination" style="display: flex; justify-content: flex-end;"></div>
<?php endif; ?>
</div>
<?php
}
Explanation about changes:
The pagination dots div .my-custom-swiper-pagination.swiper-pagination is placed outside the .swiper-wrapper, but inside the main .my-custom-portfolio-list container, so it renders once per slider.
The footer div inside each slide has three flex children:
.my-custom-title (flex: 1, left)
.my-custom-category (fixed ~65% width, centered)
No pagination dots here .
The inline styles on the footer and children replicate the flex layout you want — you can alternatively move them to CSS if preferred.
This clean semantic structure matches your goal perfectly.
Next step after you update this: To complete the fix, also update the CSS for .my-custom-portfolio-list-item-footer and related classes accordingly — I can provide the CSS snippet next if you want.
If you want me to improve or provide the matching final CSS block for this layout now, just ask!
/* Ensure media and footer remain clickable */
.my-custom-portfolio-list-item-media,
.my-custom-portfolio-list-item-footer {
position: relative;
z-index: 1;
}
/* === Responsive adjustments === */
@media screen and (max-width: 767px) {
.my-custom-portfolio-list-item-footer {
flex-direction: column;
align-items: flex-start;
gap: 8px;
}
code Copy code
.my-custom-swiper-pagination.swiper-pagination {
justify-content: flex-start;
margin-left: 0;
padding-left: 0;
}
Title keeps flex: 1 to fill remaining space on left.
The text-align is explicitly set: title left, category center.
The pagination dots CSS remains unchanged, since the pagination container is now outside the slide footer in the HTML: css Copy code
.my-custom-swiper-pagination.swiper-pagination {
position: relative !important;
width: auto;
display: flex;
align-items: center;
justify-content: flex-end;
margin-left: auto;
padding-left: 10px;
gap: 4px;
}
Summary:
Update the CSS only for .my-custom-portfolio-list-item-footer and its children as above.
Make sure the pagination container is ONLY the one you’re styling here — rendered once per slider (outside slides).
If you want, I can package the entire CSS file with these changes made, or you can apply these selectively inside your existing CSS.
Let me know if you want me to generate the complete updated CSS file text with these fixes included!
/* === General Widget Container === */
.elementor-widget-my-custom-portfolio-list {
position: relative;
width: 100%;
overflow: hidden;
}
/* === Swiper Container and Slides === */
.my-custom-portfolio-list {
width: 100%;
overflow: hidden;
}
.swiper-slide {
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-start;
padding-bottom: 50px;
width: 100%;
flex-shrink: 0;
box-sizing: border-box;
}
/* === Portfolio Item Structure === */
.my-custom-portfolio-list-item {
width: 100%;
display: flex;
flex-direction: column;
align-items: flex-start;
position: relative;
box-sizing: border-box;
}
.my-custom-portfolio-list-item-wrapper {
position: relative;
display: block;
width: 100%;
height: 100%;
}
/* === Displayed Image or Video === */
.my-custom-portfolio-list-item-media {
width: 100%;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
}
.my-custom-portfolio-list-item-media img,
.my-custom-portfolio-list-item-media video {
width: 100%;
height: 100%;
display: block;
}
.my-custom-portfolio-video-embed {
position: relative;
width: 100%;
/* Maintain 16:9 aspect ratio */
padding-bottom: 56.25%;
height: 0;
overflow: hidden;
min-height: 150px; /* fallback height */
}
.my-custom-portfolio-video-embed iframe,
.my-custom-portfolio-video-embed object,
.my-custom-portfolio-video-embed embed {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
/* === Footer with Title, Category, and Pagination Inline === */
.my-custom-portfolio-list-item-footer {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
padding-top: 10px;
gap: 10px; /* updated gap */
}
/* Title on the left */
.my-custom-title {
flex: 1;
font-weight: bold;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
text-align: left;
}
/* Category centered and approx 65% width */
.my-custom-category {
flex: 0 0 65%; /* no grow/shrink, fixed width */
text-align: center;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
/* === Inline Pagination Bullets === */
.my-custom-swiper-pagination.swiper-pagination {
position: relative !important;
width: auto;
display: flex;
align-items: center;
justify-content: flex-end;
margin-left: auto;
padding-left: 10px;
gap: 4px;
}
/* Pagination bullet styling */
.swiper-pagination-bullet {
background-color: transparent !important;
border: none !important;
opacity: 1 !important;
outline: none;
}
.my-custom-swiper-pagination .swiper-pagination-bullet {
background: #ccc;
opacity: 1;
margin: 0 5px;
position: relative;
width: 1.1rem;
height: 0.65rem;
border-radius: 999px;
transition: width 0.3s, background-color 0.3s;
}
.my-custom-swiper-pagination .swiper-pagination-bullet-active {
background: #000;
width: 1.1rem;
}
.my-custom-swiper-pagination .swiper-pagination-bullet:focus {
outline: none;
}
/* === Link Overlay Cover === */
.my-custom-portfolio-link {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 5;
opacity: 0;
}
/* Ensure media and footer remain clickable */
.my-custom-portfolio-list-item-media,
.my-custom-portfolio-list-item-footer {
position: relative;
z-index: 1;
}
/* === Responsive adjustments === */
@media screen and (max-width: 767px) {
.my-custom-portfolio-list-item-footer {
flex-direction: column;
align-items: flex-start;
gap: 8px;
}
.my-custom-swiper-pagination.swiper-pagination {
justify-content: flex-start;
margin-left: 0;
padding-left: 0;
}
}
Summary:
The .my-custom-portfolio-list-item-footer container is flex with justify-content: space-between and a modest gap for spacing.
The .my-custom-title fills remaining horizontal space on the left.
The .my-custom-category occupies about 65% width and is centered.
The pagination container (.my-custom-swiper-pagination.swiper-pagination) remains flex aligned to the right.
Responsive tweaks remain intact making the footer flex vertically stacked on smaller screen widths.
Just replace your existing CSS with this full version and refresh your browser cache (or do a hard reload). That will fix your footer layout to match your exact requested design.
If you want me to help with any other tweaks, just say!
<h3 class="my-custom-portfolio-list-item-title" style="color: {{{ settings.title_color }}}; {{ function_to_generate_typography_css_for_editor( 'title_typography', settings ) }}">
{{{ item.portfolio_item_title }}}
</h3>
<p class="my-custom-portfolio-list-item-category" style="color: {{{ settings.category_color }}}; {{ function_to_generate_typography_css_for_editor( 'category_typography', settings ) }}">
{{{ item.portfolio_item_category }}}
</p>
Step 3: Implement a JS helper for typography inline styles Since PHP helper function to generate typography CSS doesn’t exist in JS, you can implement a lightweight JS equivalent or hardcode minimal bindings like font-size, font-family, font-weight, etc., based on controls.
This is more advanced but necessary for complete live preview consistency.
Alternative (simpler) workaround for now:
Remove inline typography styles in PHP render() and do NOT override styles inline in the markup .
Instead, rely on Elementor’s automatic CSS generation linked to typography controls .
In register_controls(), make sure typography controls are registered with their selectors parameter properly targeting CSS selectors (e.g. .my-custom-portfolio-list-item-title).
Remove any style="color: ..." or inline typography in render()
Let Elementor output the aggregated CSS to editor and frontend automatically.
2. Widget NOT rendering live changes in the Elementor editor (Style tab / content updates)
Explanation:
Elementor uses content_template() for live frontend editing and preview.
If content_template() is incomplete or misses applying critical controls, changes won't reflect live in editor.
Your content_template() must mirror the PHP render() output as closely as possible, including:
Typography styling,
Colors,
Content structure.
Missing or partial content_template() implementation causes live preview issues.
3. Widget NOT rendering portfolio items correctly in Elementor editor (only first item shows)
Likely cause:
Action plan and concrete corrections
I. Adjust register_controls() for typography controls
Make sure controls like title_typography and category_typography define the selectors properly:
php Copy code
$this->add_group_control(
\Elementor\Group_Control_Typography::get_type(),
[
'name' => 'title_typography',
'label' => esc_html__( 'Title Typography', 'my-custom-portfolio-widget' ),
'selector' => '{{WRAPPER}} .my-custom-portfolio-list-item-title',
]
);
$this->add_group_control(
\Elementor\Group_Control_Typography::get_type(),
[
'name' => 'category_typography',
'label' => esc_html__( 'Category Typography', 'my-custom-portfolio-widget' ),
'selector' => '{{WRAPPER}} .my-custom-portfolio-list-item-category',
]
);
II. Modify content_template() to output the markup with classes and direct binding only for color (color control usually works as inline style, or better moved to selectors if buggy). Sample snippet inside content_template():
js Copy code
<h3 class="my-custom-portfolio-list-item-title" style="color: {{{ settings.title_color }}}">
{{{ item.portfolio_item_title }}}
</h3>
<p class="my-custom-portfolio-list-item-category" style="color: {{{ settings.category_color }}}">
{{{ item.portfolio_item_category }}}
</p>
Do not inline typography CSS here . Let Elementor CSS handle it, or you can later extend with JS to try picking typography (font-family, size) from settings.
III. Fix the loop in content_template() Make sure that the _.each() loop runs over all settings.portfolio_items properly, not just renders the first one.
Example snippet (simplified) inside content_template():
js Copy code
<# if ( settings.portfolio_items && settings.portfolio_items.length ) { #>
<div class="my-custom-portfolio-list swiper-container" data-swiper-options='{{ JSON.stringify( swiperOptions ) }}'>
<div class="swiper-wrapper">
<# _.each( settings.portfolio_items, function( item ) { #>
<div class="swiper-slide my-custom-portfolio-list-item">
<!-- your markup -->
</div>
<# }); #>
</div>
<!-- pagination, navigation here -->
</div>
<# } #>
IV. Clear caches, regenerate CSS and do a hard reload after these changes in Elementor editor.
Summary — Quick checklist for you to fix all 3 issues: Step Where to edit What to do 1 register_controls()Use typography controls with proper selectors attribute 2 render()Remove inline typography and color styles, rely on CSS selectors 3 content_template()Mirror PHP markup, apply color inline only, avoid inline typography, ensure iteration over all items 4 Frontend & editor browsers caching Clear cache, regenerate Elementor CSS, hard reload page
If you want, I can prepare corrected full code snippets for your register_controls(), render(), and content_template() methods exactly reflecting these changes. Just let me know!
<h3 class="my-custom-portfolio-list-item-title" style="color: <?php echo esc_attr( $settings['title_color'] ); ?>; <?php echo $this->get_inline_typography_css( $settings, 'title_typography' ); ?>">
<?php echo esc_html( $item['portfolio_item_title'] ); ?>
</h3>
<p class="my-custom-portfolio-list-item-category" style="color: <?php echo esc_attr( $settings['category_color'] ); ?>; <?php echo $this->get_inline_typography_css( $settings, 'category_typography' ); ?>">
<?php echo esc_html( $item['portfolio_item_category'] ); ?>
</p>
php Copy code
<h3 class="my-custom-portfolio-list-item-title">
<?php echo esc_html( $item['portfolio_item_title'] ); ?>
</h3>
<p class="my-custom-portfolio-list-item-category">
<?php echo esc_html( $item['portfolio_item_category'] ); ?>
</p>
Paste this directly in your render() method in place of the old markup (inside the slide loop).
Step 3: Update content_template() Method for Live Editor Preview
File: widgets/portfolio-list-widget.php
Function / Method:
What to do: Replace your entire content_template() method with this complete corrected version:
php Copy code
protected function content_template() {
?>
<#
var swiperOptions = {
slidesPerView: settings.slides_per_view,
spaceBetween: settings.space_between,
loop: ( 'yes' === settings.loop_carousel ),
autoplay: ( 'yes' === settings.autoplay ) ? { delay: settings.autoplay_delay } : false,
navigation: ( 'yes' === settings.show_navigation ) ? { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev' } : false,
pagination: ( 'yes' === settings.show_pagination ) ? { el: '.swiper-pagination', clickable: true } : false,
breakpoints: {
640: { slidesPerView: 1, spaceBetween: 20 },
768: { slidesPerView: 2, spaceBetween: 40 },
1024: { slidesPerView: settings.slides_per_view, spaceBetween: settings.space_between },
},
};
if ( ! settings.portfolio_items || ! settings.portfolio_items.length ) {
return;
}
#>
<div class="my-custom-portfolio-list swiper-container" data-swiper-options='{{ JSON.stringify( swiperOptions ) }}'>
<div class="swiper-wrapper">
<# _.each( settings.portfolio_items, function( item ) {
var link_url = item.portfolio_item_link.url;
var link_target = item.portfolio_item_link.is_external ? '_blank' : '_self';
var link_nofollow = item.portfolio_item_link.nofollow ? 'nofollow' : '';
var media_html = '';
if ( 'image' === item.media_type ) {
var image = {
id: item.portfolio_item_image.id,
url: item.portfolio_item_image.url,
size: item.portfolio_item_image.size,
dimension: item.portfolio_item_image.dimension,
model: item._image,
};
var image_url = elementor.imagesManager.getImageUrl( image );
media_html = '<img src="' + image_url + '" alt="' + item.portfolio_item_title + '">';
} else if ( 'self_hosted_video' === item.media_type && item.portfolio_item_video && item.portfolio_item_video.url ) {
media_html = '<video controls muted playsinline><source src="' + item.portfolio_item_video.url + '" type="' + item.portfolio_item_video.mime + '">Your browser does not support the video tag.</video>';
} else if ( 'youtube' === item.media_type && item.youtube_video_url && item.youtube_video_url.url ) {
var youtube_id = item.youtube_video_url.url.match(/(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})/);
if ( youtube_id && youtube_id[1] ) {
media_html = '<div class="my-custom-portfolio-video-embed"><iframe src="https://www.youtube.com/embed/' + youtube_id[1] + '?controls=0&showinfo=0&rel=0&autoplay=0&loop=0&mute=1" frameborder="0" allowfullscreen allow="autoplay"></iframe></div>';
}
} else if ( 'vimeo' === item.media_type && item.vimeo_video_url && item.vimeo_video_url.url ) {
var vimeo_id = item.vimeo_video_url.url.match(/(?:vimeo\.com\/)(?:channels\/[^\/]+\/|groups\/[^\/]+\/videos\/|album\/\d+\/video\/|video\/|)(\d+)/);
if ( vimeo_id && vimeo_id[1] ) {
media_html = '<div class="my-custom-portfolio-video-embed"><iframe src="https://player.vimeo.com/video/' + vimeo_id[1] + '?autoplay=0&loop=0&autopause=0&muted=1" frameborder="0" allowfullscreen allow="autoplay"></iframe></div>';
}
}
#>
<div class="swiper-slide my-custom-portfolio-list-item">
<# if ( link_url && link_url !== '#' ) { #>
<a href="{{ link_url }}" target="{{ link_target }}" rel="{{ link_nofollow }}">
<# } #>
<div class="my-custom-portfolio-list-item-media">
{{{ media_html }}}
</div>
<div class="my-custom-portfolio-list-item-footer" style="display: flex; align-items: center; justify-content: space-between; width: 100%; padding-top: 10px; gap: 10px;">
<div class="my-custom-title" style="flex: 1; text-align: left; color: {{{ settings.title_color }}};">
{{{ item.portfolio_item_title }}}
</div>
<div class="my-custom-category" style="flex: 0 0 65%; text-align: center; color: {{{ settings.category_color }}};">
{{{ item.portfolio_item_category }}}
</div>
</div>
<# if ( link_url && link_url !== '#' ) { #>
</a>
<# } #>
</div>
<# }); #>
</div>
<# if ( 'yes' === settings.show_navigation ) { #>
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
<# } #>
<# if ( 'yes' === settings.show_pagination ) { #>
<div class="my-custom-swiper-pagination swiper-pagination" style="display: flex; justify-content: flex-end;"></div>
<# } #>
</div>
<?php
}
Where to paste:
In widgets/portfolio-list-widget.php
Replace the entire current content_template() method with the above code.
Final Notes:
This fully mirrors your PHP render() output layout but avoids inline typography styles (let Elementor’s CSS handle that via selectors).
Colors for title and category are applied inline in editor preview only.
Loops through all portfolio items , ensuring all show correctly in live editor.
Single pagination dots container outside the loop.
Summary for you to copy/paste: File Method Action widgets/portfolio-list-widget.phpregister_controls()Replace typography controls as in Step 1 widgets/portfolio-list-widget.phprender()Remove inline typography/color styles as in Step 2 widgets/portfolio-list-widget.phpcontent_template()Replace fully with corrected version in Step 3
If you want me to provide each method’s full exact code , just say so and I’ll prepare them!
Feel free to ask anything, I’m here to help you make this widget perfect!
$repeater = new Repeater();
$repeater->add_control(
'portfolio_item_title',
[
'label' => esc_html__( 'Title', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::TEXT,
'default' => esc_html__( 'Portfolio Item Title', 'my-custom-portfolio-widget' ),
'placeholder' => esc_html__( 'Enter your title', 'my-custom-portfolio-widget' ),
'label_block' => true,
]
);
$repeater->add_control(
'portfolio_item_category',
[
'label' => esc_html__( 'Category', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::TEXT,
'default' => esc_html__( 'Category Name', 'my-custom-portfolio-widget' ),
'placeholder' => esc_html__( 'Enter category', 'my-custom-portfolio-widget' ),
'label_block' => true,
]
);
$repeater->add_control(
'media_type',
[
'label' => esc_html__( 'Media Type', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::SELECT,
'default' => 'image',
'options' => [
'image' => esc_html__( 'Image', 'my-custom-portfolio-widget' ),
'self_hosted_video' => esc_html__( 'Self-Hosted Video', 'my-custom-portfolio-widget' ),
'youtube' => esc_html__( 'YouTube Video', 'my-custom-portfolio-widget' ),
'vimeo' => esc_html__( 'Vimeo Video', 'my-custom-portfolio-widget' ),
],
]
);
$repeater->add_control(
'portfolio_item_image',
[
'label' => esc_html__( 'Image', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::MEDIA,
'default' => [ 'url' => Utils::get_placeholder_image_src() ],
'condition' => [ 'media_type' => 'image' ],
]
);
$repeater->add_control(
'portfolio_item_video',
[
'label' => esc_html__( 'Self-Hosted Video', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::MEDIA,
'media_type' => 'video',
'condition' => [ 'media_type' => 'self_hosted_video' ],
]
);
$repeater->add_control(
'youtube_video_url',
[
'label' => esc_html__( 'YouTube Video URL', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::URL,
'placeholder' => esc_html__( 'http://youtube.com/watch?v=VIDEO_ID', 'my-custom-portfolio-widget' ),
'label_block' => true,
'show_external' => false,
'condition' => [ 'media_type' => 'youtube' ],
]
);
$repeater->add_control(
'vimeo_video_url',
[
'label' => esc_html__( 'Vimeo Video URL', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::URL,
'placeholder' => esc_html__( 'https://vimeo.com/VIDEO_ID', 'my-custom-portfolio-widget' ),
'label_block' => true,
'show_external' => false,
'condition' => [ 'media_type' => 'vimeo' ],
]
);
$repeater->add_control(
'portfolio_item_link',
[
'label' => esc_html__( 'Link', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::URL,
'placeholder' => esc_html__( 'https://your-link.com', 'my-custom-portfolio-widget' ),
'show_external' => true,
'default' => [
'url' => '#',
'is_external' => true,
'nofollow' => true,
],
]
);
$this->add_control(
'portfolio_items',
[
'label' => esc_html__( 'Portfolio Items', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::REPEATER,
'fields' => $repeater->get_controls(),
'default' => [
[
'portfolio_item_title' => esc_html__( 'Portfolio #1', 'my-custom-portfolio-widget' ),
'portfolio_item_category' => esc_html__( 'Design', 'my-custom-portfolio-widget' ),
'media_type' => 'image',
],
[
'portfolio_item_title' => esc_html__( 'Portfolio #2', 'my-custom-portfolio-widget' ),
'portfolio_item_category' => esc_html__( 'Development', 'my-custom-portfolio-widget' ),
'media_type' => 'image',
],
],
'title_field' => '{{{ portfolio_item_title }}}',
]
);
$this->end_controls_section();
// Style Section
$this->start_controls_section(
'section_style',
[
'label' => esc_html__( 'Portfolio List Style', 'my-custom-portfolio-widget' ),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->add_control(
'item_background_color',
[
'label' => esc_html__( 'Item Background Color', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .my-custom-portfolio-list-item' => 'background-color: {{VALUE}};',
],
]
);
$this->add_control(
'media_height',
[
'label' => esc_html__( 'Media Height', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::SLIDER,
'size_units' => [ 'px', 'vh', 'em', '%' ],
'range' => [
'px' => [ 'min' => 0, 'max' => 1000 ],
'vh' => [ 'min' => 0, 'max' => 100 ],
'%' => [ 'min' => 0, 'max' => 100 ],
],
'default' => [ 'unit' => 'vh', 'size' => 80 ],
'selectors' => [
'{{WRAPPER}} .my-custom-portfolio-list-item-media' => 'height: {{SIZE}}{{UNIT}};',
],
]
);
$this->add_control(
'media_object_fit',
[
'label' => esc_html__( 'Media Fit', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::SELECT,
'default' => 'cover',
'options' => [
'fill' => esc_html__( 'Fill', 'my-custom-portfolio-widget' ),
'cover' => esc_html__( 'Cover', 'my-custom-portfolio-widget' ),
'contain' => esc_html__( 'Contain', 'my-custom-portfolio-widget' ),
'none' => esc_html__( 'None', 'my-custom-portfolio-widget' ),
],
'selectors' => [
'{{WRAPPER}} .my-custom-portfolio-list-item-media img, {{WRAPPER}} .my-custom-portfolio-list-item-media video, {{WRAPPER}} .my-custom-portfolio-video-embed iframe' => 'object-fit: {{VALUE}};',
],
]
);
$this->add_control(
'media_object_position',
[
'label' => esc_html__( 'Media Alignment (Object Position)', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::SELECT,
'default' => 'center',
'options' => [
'center' => esc_html__( 'Center', 'my-custom-portfolio-widget' ),
'top' => esc_html__( 'Top', 'my-custom-portfolio-widget' ),
'bottom' => esc_html__( 'Bottom', 'my-custom-portfolio-widget' ),
'left' => esc_html__( 'Left', 'my-custom-portfolio-widget' ),
'right' => esc_html__( 'Right', 'my-custom-portfolio-widget' ),
'top left' => esc_html__( 'Top Left', 'my-custom-portfolio-widget' ),
'top right' => esc_html__( 'Top Right', 'my-custom-portfolio-widget' ),
'bottom left' => esc_html__( 'Bottom Left', 'my-custom-portfolio-widget' ),
'bottom right' => esc_html__( 'Bottom Right', 'my-custom-portfolio-widget' ),
],
'selectors' => [
'{{WRAPPER}} .my-custom-portfolio-list-item-media img, {{WRAPPER}} .my-custom-portfolio-list-item-media video, {{WRAPPER}} .my-custom-portfolio-video-embed iframe' => 'object-position: {{VALUE}};',
],
]
);
$this->add_control(
'text_alignment',
[
'label' => esc_html__( 'Text Alignment', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::CHOOSE,
'options' => [
'flex-start' => [
'title' => esc_html__( 'Left', 'my-custom-portfolio-widget' ),
'icon' => 'eicon-text-align-left',
],
'center' => [
'title' => esc_html__( 'Center', 'my-custom-portfolio-widget' ),
'icon' => 'eicon-text-align-center',
],
'flex-end' => [
'title' => esc_html__( 'Right', 'my-custom-portfolio-widget' ),
'icon' => 'eicon-text-align-right',
],
],
'default' => 'flex-start',
'toggle' => true,
'selectors' => [
'{{WRAPPER}} .my-custom-portfolio-list-item-info' => 'justify-content: {{VALUE}};',
],
]
);
$this->add_control(
'title_color',
[
'label' => esc_html__( 'Title Color', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .my-custom-portfolio-list-item-title' => 'color: {{VALUE}};',
],
]
);
$this->add_group_control(
\Elementor\Group_Control_Typography::get_type(),
[
'name' => 'title_typography',
'label' => esc_html__( 'Title Typography', 'my-custom-portfolio-widget' ),
'selector' => '{{WRAPPER}} .my-custom-portfolio-list-item-title',
]
);
$this->add_control(
'category_color',
[
'label' => esc_html__( 'Category Color', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .my-custom-portfolio-list-item-category' => 'color: {{VALUE}};',
],
]
);
$this->add_group_control(
\Elementor\Group_Control_Typography::get_type(),
[
'name' => 'category_typography',
'label' => esc_html__( 'Category Typography', 'my-custom-portfolio-widget' ),
'selector' => '{{WRAPPER}} .my-custom-portfolio-list-item-category',
]
);
$this->end_controls_section();
// Carousel Settings Section
$this->start_controls_section(
'section_swiper_settings',
[
'label' => esc_html__( 'Carousel Settings', 'my-custom-portfolio-widget' ),
'tab' => Controls_Manager::TAB_CONTENT,
]
);
$this->add_control(
'slides_per_view',
[
'label' => esc_html__( 'Slides Per View', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::NUMBER,
'min' => 1,
'max' => 10,
'step' => 1,
'default' => 3,
]
);
$this->add_control(
'space_between',
[
'label' => esc_html__( 'Space Between Slides', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::NUMBER,
'min' => 0,
'max' => 100,
'step' => 1,
'default' => 30,
]
);
$this->add_control(
'loop_carousel',
[
'label' => esc_html__( 'Loop Carousel', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::SWITCHER,
'label_on' => esc_html__( 'Yes', 'my-custom-portfolio-widget' ),
'label_off' => esc_html__( 'No', 'my-custom-portfolio-widget' ),
'return_value' => 'yes',
'default' => 'no',
]
);
$this->add_control(
'autoplay',
[
'label' => esc_html__( 'Autoplay', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::SWITCHER,
'label_on' => esc_html__( 'Yes', 'my-custom-portfolio-widget' ),
'label_off' => esc_html__( 'No', 'my-custom-portfolio-widget' ),
'return_value' => 'yes',
'default' => 'no',
]
);
$this->add_control(
'autoplay_delay',
[
'label' => esc_html__( 'Autoplay Delay (ms)', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::NUMBER,
'min' => 1000,
'max' => 10000,
'step' => 100,
'default' => 3000,
'condition' => [ 'autoplay' => 'yes' ],
]
);
$this->add_control(
'show_navigation',
[
'label' => esc_html__( 'Navigation Arrows', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::SWITCHER,
'label_on' => esc_html__( 'Show', 'my-custom-portfolio-widget' ),
'label_off' => esc_html__( 'Hide', 'my-custom-portfolio-widget' ),
'return_value' => 'yes',
'default' => 'yes',
]
);
$this->add_control(
'show_pagination',
[
'label' => esc_html__( 'Pagination Dots', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::SWITCHER,
'label_on' => esc_html__( 'Show', 'my-custom-portfolio-widget' ),
'label_off' => esc_html__( 'Hide', 'my-custom-portfolio-widget' ),
'return_value' => 'yes',
'default' => 'yes',
]
);
$this->add_control(
'pagination_bottom_offset',
[
'label' => esc_html__( 'Pagination Dots Offset From Bottom', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::SLIDER,
'size_units' => [ 'px', '%' ],
'range' => [
'px' => [ 'min' => -100, 'max' => 200 ],
'%' => [ 'min' => -50, 'max' => 100 ],
],
'default' => [ 'unit' => 'px', 'size' => 0 ],
'condition' => [ 'show_pagination' => 'yes' ],
'selectors' => [
'{{WRAPPER}} .my-custom-swiper-pagination.swiper-pagination' => 'bottom: {{SIZE}}{{UNIT}};',
],
]
);
$this->end_controls_section();
}
protected function register_controls() {
// Content Section
$this->start_controls_section(
'section_content',
[
'label' => esc_html__( 'Portfolio List Content', 'my-custom-portfolio-widget' ),
'tab' => Controls_Manager::TAB_CONTENT,
]
);
$repeater = new Repeater();
$repeater->add_control(
'portfolio_item_title',
[
'label' => esc_html__( 'Title', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::TEXT,
'default' => esc_html__( 'Portfolio Item Title', 'my-custom-portfolio-widget' ),
'placeholder' => esc_html__( 'Enter your title', 'my-custom-portfolio-widget' ),
'label_block' => true,
]
);
$repeater->add_control(
'portfolio_item_category',
[
'label' => esc_html__( 'Category', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::TEXT,
'default' => esc_html__( 'Category Name', 'my-custom-portfolio-widget' ),
'placeholder' => esc_html__( 'Enter category', 'my-custom-portfolio-widget' ),
'label_block' => true,
]
);
$repeater->add_control(
'media_type',
[
'label' => esc_html__( 'Media Type', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::SELECT,
'default' => 'image',
'options' => [
'image' => esc_html__( 'Image', 'my-custom-portfolio-widget' ),
'self_hosted_video' => esc_html__( 'Self-Hosted Video', 'my-custom-portfolio-widget' ),
'youtube' => esc_html__( 'YouTube Video', 'my-custom-portfolio-widget' ),
'vimeo' => esc_html__( 'Vimeo Video', 'my-custom-portfolio-widget' ),
],
]
);
$repeater->add_control(
'portfolio_item_image',
[
'label' => esc_html__( 'Image', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::MEDIA,
'default' => [ 'url' => Utils::get_placeholder_image_src() ],
'condition' => [ 'media_type' => 'image' ],
]
);
$repeater->add_control(
'portfolio_item_video',
[
'label' => esc_html__( 'Self-Hosted Video', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::MEDIA,
'media_type' => 'video',
'condition' => [ 'media_type' => 'self_hosted_video' ],
]
);
$repeater->add_control(
'youtube_video_url',
[
'label' => esc_html__( 'YouTube Video URL', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::URL,
'placeholder' => esc_html__( 'http://youtube.com/watch?v=VIDEO_ID', 'my-custom-portfolio-widget' ),
'label_block' => true,
'show_external' => false,
'condition' => [ 'media_type' => 'youtube' ],
]
);
$repeater->add_control(
'vimeo_video_url',
[
'label' => esc_html__( 'Vimeo Video URL', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::URL,
'placeholder' => esc_html__( 'https://vimeo.com/VIDEO_ID', 'my-custom-portfolio-widget' ),
'label_block' => true,
'show_external' => false,
'condition' => [ 'media_type' => 'vimeo' ],
]
);
$repeater->add_control(
'portfolio_item_link',
[
'label' => esc_html__( 'Link', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::URL,
'placeholder' => esc_html__( 'https://your-link.com', 'my-custom-portfolio-widget' ),
'show_external' => true,
'default' => [
'url' => '#',
'is_external' => true,
'nofollow' => true,
],
]
);
$this->add_control(
'portfolio_items',
[
'label' => esc_html__( 'Portfolio Items', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::REPEATER,
'fields' => $repeater->get_controls(),
'default' => [
[
'portfolio_item_title' => esc_html__( 'Portfolio #1', 'my-custom-portfolio-widget' ),
'portfolio_item_category' => esc_html__( 'Design', 'my-custom-portfolio-widget' ),
'media_type' => 'image',
],
[
'portfolio_item_title' => esc_html__( 'Portfolio #2', 'my-custom-portfolio-widget' ),
'portfolio_item_category' => esc_html__( 'Development', 'my-custom-portfolio-widget' ),
'media_type' => 'image',
],
],
'title_field' => '{{{ portfolio_item_title }}}',
]
);
$this->end_controls_section();
// Style Section
$this->start_controls_section(
'section_style',
[
'label' => esc_html__( 'Portfolio List Style', 'my-custom-portfolio-widget' ),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->add_control(
'item_background_color',
[
'label' => esc_html__( 'Item Background Color', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .my-custom-portfolio-list-item' => 'background-color: {{VALUE}};',
],
]
);
$this->add_control(
'media_height',
[
'label' => esc_html__( 'Media Height', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::SLIDER,
'size_units' => [ 'px', 'vh', 'em', '%' ],
'range' => [
'px' => [ 'min' => 0, 'max' => 1000 ],
'vh' => [ 'min' => 0, 'max' => 100 ],
'%' => [ 'min' => 0, 'max' => 100 ],
],
'default' => [ 'unit' => 'vh', 'size' => 80 ],
'selectors' => [
'{{WRAPPER}} .my-custom-portfolio-list-item-media' => 'height: {{SIZE}}{{UNIT}};',
],
]
);
$this->add_control(
'media_object_fit',
[
'label' => esc_html__( 'Media Fit', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::SELECT,
'default' => 'cover',
'options' => [
'fill' => esc_html__( 'Fill', 'my-custom-portfolio-widget' ),
'cover' => esc_html__( 'Cover', 'my-custom-portfolio-widget' ),
'contain' => esc_html__( 'Contain', 'my-custom-portfolio-widget' ),
'none' => esc_html__( 'None', 'my-custom-portfolio-widget' ),
],
'selectors' => [
'{{WRAPPER}} .my-custom-portfolio-list-item-media img, {{WRAPPER}} .my-custom-portfolio-list-item-media video, {{WRAPPER}} .my-custom-portfolio-video-embed iframe' => 'object-fit: {{VALUE}};',
],
]
);
$this->add_control(
'media_object_position',
[
'label' => esc_html__( 'Media Alignment (Object Position)', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::SELECT,
'default' => 'center',
'options' => [
'center' => esc_html__( 'Center', 'my-custom-portfolio-widget' ),
'top' => esc_html__( 'Top', 'my-custom-portfolio-widget' ),
'bottom' => esc_html__( 'Bottom', 'my-custom-portfolio-widget' ),
'left' => esc_html__( 'Left', 'my-custom-portfolio-widget' ),
'right' => esc_html__( 'Right', 'my-custom-portfolio-widget' ),
'top left' => esc_html__( 'Top Left', 'my-custom-portfolio-widget' ),
'top right' => esc_html__( 'Top Right', 'my-custom-portfolio-widget' ),
'bottom left' => esc_html__( 'Bottom Left', 'my-custom-portfolio-widget' ),
'bottom right' => esc_html__( 'Bottom Right', 'my-custom-portfolio-widget' ),
],
'selectors' => [
'{{WRAPPER}} .my-custom-portfolio-list-item-media img, {{WRAPPER}} .my-custom-portfolio-list-item-media video, {{WRAPPER}} .my-custom-portfolio-video-embed iframe' => 'object-position: {{VALUE}};',
],
]
);
$this->add_control(
'text_alignment',
[
'label' => esc_html__( 'Text Alignment', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::CHOOSE,
'options' => [
'flex-start' => [
'title' => esc_html__( 'Left', 'my-custom-portfolio-widget' ),
'icon' => 'eicon-text-align-left',
],
'center' => [
'title' => esc_html__( 'Center', 'my-custom-portfolio-widget' ),
'icon' => 'eicon-text-align-center',
],
'flex-end' => [
'title' => esc_html__( 'Right', 'my-custom-portfolio-widget' ),
'icon' => 'eicon-text-align-right',
],
],
'default' => 'flex-start',
'toggle' => true,
'selectors' => [
'{{WRAPPER}} .my-custom-portfolio-list-item-info' => 'justify-content: {{VALUE}};',
],
]
);
$this->add_control(
'title_color',
[
'label' => esc_html__( 'Title Color', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .my-custom-portfolio-list-item-title' => 'color: {{VALUE}};',
],
]
);
$this->add_group_control(
\Elementor\Group_Control_Typography::get_type(),
[
'name' => 'title_typography',
'label' => esc_html__( 'Title Typography', 'my-custom-portfolio-widget' ),
'selector' => '{{WRAPPER}} .my-custom-portfolio-list-item-title',
]
);
$this->add_control(
'category_color',
[
'label' => esc_html__( 'Category Color', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .my-custom-portfolio-list-item-category' => 'color: {{VALUE}};',
],
]
);
$this->add_group_control(
\Elementor\Group_Control_Typography::get_type(),
[
'name' => 'category_typography',
'label' => esc_html__( 'Category Typography', 'my-custom-portfolio-widget' ),
'selector' => '{{WRAPPER}} .my-custom-portfolio-list-item-category',
]
);
$this->end_controls_section();
// Carousel Settings Section
$this->start_controls_section(
'section_swiper_settings',
[
'label' => esc_html__( 'Carousel Settings', 'my-custom-portfolio-widget' ),
'tab' => Controls_Manager::TAB_CONTENT,
]
);
$this->add_control(
'slides_per_view',
[
'label' => esc_html__( 'Slides Per View', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::NUMBER,
'min' => 1,
'max' => 10,
'step' => 1,
'default' => 3,
]
);
$this->add_control(
'space_between',
[
'label' => esc_html__( 'Space Between Slides', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::NUMBER,
'min' => 0,
'max' => 100,
'step' => 1,
'default' => 30,
]
);
$this->add_control(
'loop_carousel',
[
'label' => esc_html__( 'Loop Carousel', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::SWITCHER,
'label_on' => esc_html__( 'Yes', 'my-custom-portfolio-widget' ),
'label_off' => esc_html__( 'No', 'my-custom-portfolio-widget' ),
'return_value' => 'yes',
'default' => 'no',
]
);
$this->add_control(
'autoplay',
[
'label' => esc_html__( 'Autoplay', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::SWITCHER,
'label_on' => esc_html__( 'Yes', 'my-custom-portfolio-widget' ),
'label_off' => esc_html__( 'No', 'my-custom-portfolio-widget' ),
'return_value' => 'yes',
'default' => 'no',
]
);
$this->add_control(
'autoplay_delay',
[
'label' => esc_html__( 'Autoplay Delay (ms)', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::NUMBER,
'min' => 1000,
'max' => 10000,
'step' => 100,
'default' => 3000,
'condition' => [ 'autoplay' => 'yes' ],
]
);
$this->add_control(
'show_navigation',
[
'label' => esc_html__( 'Navigation Arrows', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::SWITCHER,
'label_on' => esc_html__( 'Show', 'my-custom-portfolio-widget' ),
'label_off' => esc_html__( 'Hide', 'my-custom-portfolio-widget' ),
'return_value' => 'yes',
'default' => 'yes',
]
);
$this->add_control(
'show_pagination',
[
'label' => esc_html__( 'Pagination Dots', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::SWITCHER,
'label_on' => esc_html__( 'Show', 'my-custom-portfolio-widget' ),
'label_off' => esc_html__( 'Hide', 'my-custom-portfolio-widget' ),
'return_value' => 'yes',
'default' => 'yes',
]
);
$this->add_control(
'pagination_bottom_offset',
[
'label' => esc_html__( 'Pagination Dots Offset From Bottom', 'my-custom-portfolio-widget' ),
'type' => Controls_Manager::SLIDER,
'size_units' => [ 'px', '%' ],
'range' => [
'px' => [ 'min' => -100, 'max' => 200 ],
'%' => [ 'min' => -50, 'max' => 100 ],
],
'default' => [ 'unit' => 'px', 'size' => 0 ],
'condition' => [ 'show_pagination' => 'yes' ],
'selectors' => [
'{{WRAPPER}} .my-custom-swiper-pagination.swiper-pagination' => 'bottom: {{SIZE}}{{UNIT}};',
],
]
);
$this->end_controls_section();
}
How to implement:
Replace your entire existing register_controls() method in the widgets/portfolio-list-widget.php file with the above.
This will correctly apply typography controls with selectors, allowing Elementor to handle font changes on live editor and frontend.
If you want me to assist with the next steps (render() and content_template()), just tell me!
if ( empty( $items ) ) {
return;
}
$swiper_options = [
'slidesPerView' => $settings['slides_per_view'],
'spaceBetween' => $settings['space_between'],
'loop' => ( 'yes' === $settings['loop_carousel'] ),
'autoplay' => ( 'yes' === $settings['autoplay'] ) ? ['delay' => $settings['autoplay_delay']] : false,
'navigation' => ( 'yes' === $settings['show_navigation'] ) ? ['nextEl' => '.swiper-button-next', 'prevEl' => '.swiper-button-prev'] : false,
'pagination' => ( 'yes' === $settings['show_pagination'] ) ? ['el' => '.swiper-pagination', 'clickable' => true] : false,
'breakpoints' => [
640 => ['slidesPerView' => 1, 'spaceBetween' => 20],
768 => ['slidesPerView' => 2, 'spaceBetween' => 40],
1024 => [
'slidesPerView' => $settings['slides_per_view'],
'spaceBetween' => $settings['space_between'],
],
],
];
?>
<div class="my-custom-portfolio-list swiper-container" data-swiper-options='<?php echo wp_json_encode( $swiper_options ); ?>'>
<div class="swiper-wrapper">
<?php foreach ( $items as $item ) :
$link_url = $item['portfolio_item_link']['url'] ?? '';
$link_target = ! empty( $item['portfolio_item_link']['is_external'] ) ? '_blank' : '_self';
$link_nofollow = ! empty( $item['portfolio_item_link']['nofollow'] ) ? 'nofollow' : '';
?>
<div class="swiper-slide my-custom-portfolio-list-item">
<?php if ( ! empty( $link_url ) && $link_url !== '#' ) : ?>
<a class="my-custom-portfolio-link" href="<?php echo esc_url( $link_url ); ?>" target="<?php echo esc_attr( $link_target ); ?>" rel="<?php echo esc_attr( $link_nofollow ); ?>">
<?php endif; ?>
<div class="my-custom-portfolio-list-item-media">
<?php
switch ( $item['media_type'] ) {
case 'image':
echo Group_Control_Image_Size::get_attachment_image_html( $item, 'full', 'portfolio_item_image' );
break;
case 'self_hosted_video':
if ( ! empty( $item['portfolio_item_video']['url'] ) ) : ?>
<video controls muted playsinline>
<source src="<?php echo esc_url( $item['portfolio_item_video']['url'] ); ?>" type="<?php echo esc_attr( $item['portfolio_item_video']['mime'] ); ?>">
<?php esc_html_e( 'Your browser does not support the video tag.', 'my-custom-portfolio-widget' ); ?>
</video>
<?php endif;
break;
case 'youtube':
$youtube_id = $this->get_youtube_id( $item['youtube_video_url']['url'] ?? '' );
if ( $youtube_id ) : ?>
<div class="my-custom-portfolio-video-embed">
<iframe src="https://www.youtube.com/embed/<?php echo esc_attr( $youtube_id ); ?>?controls=0&showinfo=0&rel=0&autoplay=0&loop=0&mute=1" frameborder="0" allowfullscreen allow="autoplay"></iframe>
</div>
<?php endif;
break;
case 'vimeo':
$vimeo_id = $this->get_vimeo_id( $item['vimeo_video_url']['url'] ?? '' );
if ( $vimeo_id ) : ?>
<div class="my-custom-portfolio-video-embed">
<iframe src="https://player.vimeo.com/video/<?php echo esc_attr( $vimeo_id ); ?>?autoplay=0&loop=0&autopause=0&muted=1" frameborder="0" allowfullscreen allow="autoplay"></iframe>
</div>
<?php endif;
break;
}
?>
</div>
<?php if ( ! empty( $link_url ) && $link_url !== '#' ) : ?>
</a>
<?php endif; ?>
<div class="my-custom-portfolio-list-item-footer" style="display: flex; align-items: center; justify-content: space-between; width: 100%; padding-top: 10px; gap: 10px;">
<div class="my-custom-title" style="flex: 1; text-align: left; color: <?php echo esc_attr( $settings['title_color'] ); ?>; <?php echo $this->get_inline_typography_css( $settings, 'title_typography' ); ?>">
<?php echo esc_html( $item['portfolio_item_title'] ); ?>
</div>
<div class="my-custom-category" style="flex: 0 0 65%; text-align: center; color: <?php echo esc_attr( $settings['category_color'] ); ?>; <?php echo $this->get_inline_typography_css( $settings, 'category_typography' ); ?>">
<?php echo esc_html( $item['portfolio_item_category'] ); ?>
</div>
<!-- NOTE: No pagination dots here -->
</div>
</div>
<?php endforeach; ?>
</div>
<?php if ( 'yes' === $settings['show_navigation'] ) : ?>
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
<?php endif; ?>
<?php if ( 'yes' === $settings['show_pagination'] ) : ?>
<div class="my-custom-swiper-pagination swiper-pagination" style="display: flex; justify-content: flex-end;"></div>
<?php endif; ?>
</div>
<?php
protected function render() {
$settings = $this->get_settings_for_display();
$items = $settings['portfolio_items'];
if ( empty( $items ) ) {
return;
}
$swiper_options = [
'slidesPerView' => $settings['slides_per_view'],
'spaceBetween' => $settings['space_between'],
'loop' => ( 'yes' === $settings['loop_carousel'] ),
'autoplay' => ( 'yes' === $settings['autoplay'] ) ? ['delay' => $settings['autoplay_delay']] : false,
'navigation' => ( 'yes' === $settings['show_navigation'] ) ? ['nextEl' => '.swiper-button-next', 'prevEl' => '.swiper-button-prev'] : false,
'pagination' => ( 'yes' === $settings['show_pagination'] ) ? ['el' => '.swiper-pagination', 'clickable' => true] : false,
'breakpoints' => [
640 => ['slidesPerView' => 1, 'spaceBetween' => 20],
768 => ['slidesPerView' => 2, 'spaceBetween' => 40],
1024 => [
'slidesPerView' => $settings['slides_per_view'],
'spaceBetween' => $settings['space_between'],
],
],
];
?>
<div class="my-custom-portfolio-list swiper-container" data-swiper-options='<?php echo wp_json_encode( $swiper_options ); ?>'>
<div class="swiper-wrapper">
<?php foreach ( $items as $item ) :
$link_url = $item['portfolio_item_link']['url'] ?? '';
$link_target = ! empty( $item['portfolio_item_link']['is_external'] ) ? '_blank' : '_self';
$link_nofollow = ! empty( $item['portfolio_item_link']['nofollow'] ) ? 'nofollow' : '';
?>
<div class="swiper-slide my-custom-portfolio-list-item">
<?php if ( ! empty( $link_url ) && $link_url !== '#' ) : ?>
<a class="my-custom-portfolio-link" href="<?php echo esc_url( $link_url ); ?>" target="<?php echo esc_attr( $link_target ); ?>" rel="<?php echo esc_attr( $link_nofollow ); ?>">
<?php endif; ?>
<div class="my-custom-portfolio-list-item-media">
<?php
switch ( $item['media_type'] ) {
case 'image':
echo Group_Control_Image_Size::get_attachment_image_html( $item, 'full', 'portfolio_item_image' );
break;
case 'self_hosted_video':
if ( ! empty( $item['portfolio_item_video']['url'] ) ) : ?>
<video controls muted playsinline>
<source src="<?php echo esc_url( $item['portfolio_item_video']['url'] ); ?>" type="<?php echo esc_attr( $item['portfolio_item_video']['mime'] ); ?>">
<?php esc_html_e( 'Your browser does not support the video tag.', 'my-custom-portfolio-widget' ); ?>
</video>
<?php endif;
break;
case 'youtube':
$youtube_id = $this->get_youtube_id( $item['youtube_video_url']['url'] ?? '' );
if ( $youtube_id ) : ?>
<div class="my-custom-portfolio-video-embed">
<iframe src="https://www.youtube.com/embed/<?php echo esc_attr( $youtube_id ); ?>?controls=0&showinfo=0&rel=0&autoplay=0&loop=0&mute=1" frameborder="0" allowfullscreen allow="autoplay"></iframe>
</div>
<?php endif;
break;
case 'vimeo':
$vimeo_id = $this->get_vimeo_id( $item['vimeo_video_url']['url'] ?? '' );
if ( $vimeo_id ) : ?>
<div class="my-custom-portfolio-video-embed">
<iframe src="https://player.vimeo.com/video/<?php echo esc_attr( $vimeo_id ); ?>?autoplay=0&loop=0&autopause=0&muted=1" frameborder="0" allowfullscreen allow="autoplay"></iframe>
</div>
<?php endif;
break;
}
?>
</div>
<?php if ( ! empty( $link_url ) && $link_url !== '#' ) : ?>
</a>
<?php endif; ?>
<div class="my-custom-portfolio-list-item-footer">
<div class="my-custom-title">
<?php echo esc_html( $item['portfolio_item_title'] ); ?>
</div>
<div class="my-custom-category">
<?php echo esc_html( $item['portfolio_item_category'] ); ?>
</div>
<!-- Pagination is not inside item footer -->
</div>
</div>
<?php endforeach; ?>
</div>
<?php if ( 'yes' === $settings['show_navigation'] ) : ?>
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
<?php endif; ?>
<?php if ( 'yes' === $settings['show_pagination'] ) : ?>
<div class="my-custom-swiper-pagination swiper-pagination"></div>
<?php endif; ?>
</div>
<?php
}
Key points about what's changed:
Removed all inline style="color: ..." and style with typography CSS.
Kept classes .my-custom-title and .my-custom-category so Elementor's own generated CSS can apply typography and color based on controls.
The pagination div is rendered only once per slider , outside the slides.
The footer div inside each slide now contains only title and category with no inline styles — so colors and fonts respond properly to Elementor style controls.
Paste this entire method in your widgets/portfolio-list-widget.php, replacing the old render() method completely.
If you want, I can next help you by giving the complete corrected content_template() method that matches this structure for live editing preview in Elementor. Would you like that?
if ( ! settings.portfolio_items || ! settings.portfolio_items.length ) {
return;
}
#>
<div class="my-custom-portfolio-list swiper-container" data-swiper-options='{{ JSON.stringify( swiperOptions ) }}'>
<div class="swiper-wrapper">
<# _.each( settings.portfolio_items, function( item ) {
var media_html = '';
if ( 'image' === item.media_type ) {
var image = {
id: item.portfolio_item_image.id,
url: item.portfolio_item_image.url,
size: item.portfolio_item_image.size,
dimension: item.portfolio_item_image.dimension,
model: item._image,
};
var image_url = elementor.imagesManager.getImageUrl( image );
media_html = '<img src="' + image_url + '" alt="' + item.portfolio_item_title + '">';
} else if ( 'self_hosted_video' === item.media_type && item.portfolio_item_video && item.portfolio_item_video.url ) {
media_html = '<video controls muted playsinline><source src="' + item.portfolio_item_video.url + '" type="' + item.portfolio_item_video.mime + '">Your browser does not support the video tag.</video>';
} else if ( 'youtube' === item.media_type && item.youtube_video_url && item.youtube_video_url.url ) {
var youtube_id = item.youtube_video_url.url.match(/(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})/);
if ( youtube_id && youtube_id[1] ) {
media_html = '<div class="my-custom-portfolio-video-embed"><iframe src="https://www.youtube.com/embed/' + youtube_id[1] + '?controls=0&showinfo=0&rel=0&autoplay=0&loop=0&mute=1" frameborder="0" allowfullscreen allow="autoplay"></iframe></div>';
}
} else if ( 'vimeo' === item.media_type && item.vimeo_video_url && item.vimeo_video_url.url ) {
var vimeo_id = item.vimeo_video_url.url.match(/(?:vimeo\.com\/)(?:channels\/[^\/]+\/|groups\/[^\/]+\/videos\/|album\/\d+\/video\/|video\/|)(\d+)/);
if ( vimeo_id && vimeo_id[1] ) {
media_html = '<div class="my-custom-portfolio-video-embed"><iframe src="https://player.vimeo.com/video/' + vimeo_id[1] + '?autoplay=0&loop=0&autopause=0&muted=1" frameborder="0" allowfullscreen allow="autoplay"></iframe></div>';
}
}
var link_url = item.portfolio_item_link.url;
var link_target = item.portfolio_item_link.is_external ? '_blank' : '_self';
var link_nofollow = item.portfolio_item_link.nofollow ? 'nofollow' : '';
#>
<div class="swiper-slide my-custom-portfolio-list-item">
<a href="{{ link_url }}" target="{{ link_target }}" rel="{{ link_nofollow }}">
<div class="my-custom-portfolio-list-item-media">
{{{ media_html }}}
</div>
<div class="my-custom-portfolio-list-item-info">
<h3 class="my-custom-portfolio-list-item-title">{{{ item.portfolio_item_title }}}</h3>
<p class="my-custom-portfolio-list-item-category">{{{ item.portfolio_item_category }}}</p>
</div>
</a>
</div>
<# } ); #>
</div>
<# if ( 'yes' === settings.show_navigation ) { #>
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
<# } #>
<# if ( 'yes' === settings.show_pagination ) { #>
<div class="my-custom-swiper-pagination swiper-pagination"></div>
<# } #>
</div>
<?php
}
protected function content_template() {
?>
<#
var swiperOptions = {
slidesPerView: settings.slides_per_view,
spaceBetween: settings.space_between,
loop: ( 'yes' === settings.loop_carousel ),
autoplay: ( 'yes' === settings.autoplay ) ? { delay: settings.autoplay_delay } : false,
navigation: ( 'yes' === settings.show_navigation ) ? { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev' } : false,
pagination: ( 'yes' === settings.show_pagination ) ? { el: '.swiper-pagination', clickable: true } : false,
breakpoints: {
640: { slidesPerView: 1, spaceBetween: 20 },
768: { slidesPerView: 2, spaceBetween: 40 },
1024: { slidesPerView: settings.slides_per_view, spaceBetween: settings.space_between }
}
};
if ( ! settings.portfolio_items || ! settings.portfolio_items.length ) {
return;
}
#>
<div class="my-custom-portfolio-list swiper-container" data-swiper-options='{{ JSON.stringify(swiperOptions) }}'>
<div class="swiper-wrapper">
<# _.each( settings.portfolio_items, function( item ) {
var mediaHtml = '';
if ( 'image' === item.media_type ) {
var image = {
id: item.portfolio_item_image.id,
url: item.portfolio_item_image.url,
size: item.portfolio_item_image.size,
dimension: item.portfolio_item_image.dimension,
model: item._image,
};
var imageUrl = elementor.imagesManager.getImageUrl( image );
mediaHtml = '<img src="' + imageUrl + '" alt="' + item.portfolio_item_title + '">';
} else if ( 'self_hosted_video' === item.media_type && item.portfolio_item_video && item.portfolio_item_video.url ) {
mediaHtml = '<video controls muted playsinline><source src="' + item.portfolio_item_video.url + '" type="' + item.portfolio_item_video.mime + '">Your browser does not support the video tag.</video>';
} else if ( 'youtube' === item.media_type && item.youtube_video_url && item.youtube_video_url.url ) {
var youtubeId = item.youtube_video_url.url.match(/(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})/);
if ( youtubeId && youtubeId[1] ) {
mediaHtml = '<div class="my-custom-portfolio-video-embed"><iframe src="https://www.youtube.com/embed/' + youtubeId[1] + '?controls=0&showinfo=0&rel=0&autoplay=0&loop=0&mute=1" frameborder="0" allowfullscreen allow="autoplay"></iframe></div>';
}
} else if ( 'vimeo' === item.media_type && item.vimeo_video_url && item.vimeo_video_url.url ) {
var vimeoId = item.vimeo_video_url.url.match(/(?:vimeo\.com\/)(?:channels\/[^\/]+\/|groups\/[^\/]+\/videos\/|album\/\d+\/video\/|video\/|)(\d+)/);
if ( vimeoId && vimeoId[1] ) {
mediaHtml = '<div class="my-custom-portfolio-video-embed"><iframe src="https://player.vimeo.com/video/' + vimeoId[1] + '?autoplay=0&loop=0&autopause=0&muted=1" frameborder="0" allowfullscreen allow="autoplay"></iframe></div>';
}
}
var linkUrl = item.portfolio_item_link.url;
var linkTarget = item.portfolio_item_link.is_external ? '_blank' : '_self';
var linkNofollow = item.portfolio_item_link.nofollow ? 'nofollow' : '';
#>
<div class="swiper-slide my-custom-portfolio-list-item">
<# if ( linkUrl && linkUrl !== '#' ) { #>
<a href="{{ linkUrl }}" target="{{ linkTarget }}" rel="{{ linkNofollow }}">
<# } #>
<div class="my-custom-portfolio-list-item-media">
{{{ mediaHtml }}}
</div>
<div class="my-custom-portfolio-list-item-footer">
<div class="my-custom-title">{{{ item.portfolio_item_title }}}</div>
<div class="my-custom-category">{{{ item.portfolio_item_category }}}</div>
</div>
<# if ( linkUrl && linkUrl !== '#' ) { #>
</a>
<# } #>
</div>
<# }); #>
</div>
<# if ( 'yes' === settings.show_navigation ) { #>
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
<# } #>
<# if ( 'yes' === settings.show_pagination ) { #>
<div class="my-custom-swiper-pagination swiper-pagination"></div>
<# } #>
</div>
<?php
}
Explanation of important corrections:
Removed inline styles for coloring and typography to allow Elementor CSS application.
Cleaned variable names to standard camelCase.
Pagination dots (.my-custom-swiper-pagination) are rendered once outside the slides for proper swiper pagination.
Footer contains only the title and category with proper classes for styling.
Supports all media types similarly to PHP render method.
Clean link wrapping that only wraps media + footer content if link is set.
How to use:
Replace entire content_template() method in your widgets/portfolio-list-widget.php file with the above.
Save and test live preview in Elementor editor, changes to styles (font, color) in style tab should now update instantly.
All portfolio items should render correctly in editor preview.
If you want, I can also help test or improve any other parts related to your widget!
Also, remove any inline styles like these in your render() and content_template() methods: php Copy code
style="color: <?php echo esc_attr( $settings['title_color'] ); ?>"
style="<?php echo $this->get_inline_typography_css( $settings, 'title_typography' ); ?>"
and also no inline color/style in JS templates.
Step 2: Verify your CSS is properly scoped and not overridden
Your CSS (portfolio-list.css) selectors like .my-custom-portfolio-list-item-title and .my-custom-portfolio-list-item-category must not be overly specific or overridden elsewhere.
Temporarily disable caching plugins and browser cache.
Use browser DevTools (Inspector) to check if Elementor’s generated CSS for typography and colors is present in the editor preview and applied or overwritten.
Step 3: Fix content_template() for full render & correct live preview Make sure your content_template() outputs all portfolio items correctly and does not wrap everything in the anchor if link is missing.
Here is a slightly improved version of your content_template() loop snippet:
js Copy code
<# _.each( settings.portfolio_items, function( item ) {
var mediaHtml = '';
// ... generate mediaHtml as before
var linkUrl = item.portfolio_item_link.url;
var linkTarget = item.portfolio_item_link.is_external ? '_blank' : '_self';
var linkNofollow = item.portfolio_item_link.nofollow ? 'nofollow' : '';
#>
<div class="swiper-slide my-custom-portfolio-list-item">
<# if ( linkUrl && linkUrl !== '#' ) { #>
<a href="{{ linkUrl }}" target="{{ linkTarget }}" rel="{{ linkNofollow }}">
<# } #>
<div class="my-custom-portfolio-list-item-media">
{{{ mediaHtml }}}
</div>
<div class="my-custom-portfolio-list-item-footer">
<div class="my-custom-title">{{{ item.portfolio_item_title }}}</div>
<div class="my-custom-category">{{{ item.portfolio_item_category }}}</div>
</div>
<# if ( linkUrl && linkUrl !== '#' ) { #>
</a>
<# } #>
</div>
<# }); #>
Step 4: Testing and debugging in Elementor Editor
Enable WordPress debugging by adding to wp-config.php
php Copy code
define( 'WP_DEBUG', true );
define( 'SCRIPT_DEBUG', true );
Open browser DevTools Console and Network tab to check for JS errors / CSS not loading.
Inspect rendered elements to verify classes and applied styles.
Temporarily remove/minify your custom CSS to see if Elementor’s styles apply correctly.
Test in an incognito browser session, disable caching plugins.
Step 5: Final fallback: Elementor's CSS regeneration
Go to Elementor > Tools > Regenerate CSS
Clear page cache and browser cache
If all the above is done, and the issue still persists:
Your current exact register_controls(), render() and content_template() methods as they are now after your changes.
Screenshots or notes from the browser inspector (especially class names and CSS applied).
Any JS errors from the console.
I’m ready to help dig in deeper once you provide those, or I can prepare full working example plugin parts that you can test as a clean baseline.
Let me know how you'd like to proceed!