Questions tagged [code-snippets]
For issues relating to the creation, use, and maintenance of code snippets.
1,931
questions
1
vote
0
answers
14
views
Render README Snippet from Relative Link
Background
I am creating the README.md for my GitHub repo ("MyRepo"), which provides certain VBA functionality. Here I wish to display a code snippet, which the user should paste into their ...
0
votes
0
answers
14
views
VS Code snippets: workaround for applying transforms to choices?
VS Code snippets have the ability to apply transforms to the inputs of a tabstop.
However, if the tabstop lists various choices for the user to pick from, as defined here, in the format described here,...
0
votes
0
answers
25
views
locked out from Wordpress with php header location
I have a wordpress site and with a code snippet created a php header location redirect. Now I have locked myself out and can no longer get to the wordpress page. Neither in the frontend nor in the ...
-3
votes
0
answers
42
views
Woocommerce - Sort items in placed orders by SKU [closed]
I'm looking for a code snippet for WooCommerce. Similar to this snippet: https://www.businessbloomer.com/woocommerce-sort-cart-items-alphabetically-az/
What I would like to have is that the products ...
0
votes
1
answer
28
views
Change 'Return to Shop' URL to the previous page in WooCommerce
I have the following snippet to which redirects the 'Return to Shop' button on an empty cart page to a specific URL:
function wc_empty_cart_redirect_url() {
return 'https://xxxxx.com/xxxx/';
}
...
0
votes
0
answers
32
views
Odoo Migration v13 to v16: Snippet Options => UncaughtPromiseError $snippet[0] undefined
In my custom module src/user/tm_web_snip_font_zsb, i have created many custom snippets. One of them is "snippets_numbers_on_vline" and has a sidebar-option to make the number of Timelines ...
1
vote
1
answer
43
views
Creating LaTeX tables in Neovim using LuaSnip snippets
When I write mathematical notes using LaTeX in Neovim, LuaSnip is very helpful. However, there's no way I can implement snippets that build different tables (tables, tabulars, arrays, etc). What ...
0
votes
1
answer
53
views
Is there a way to define custom functions for C# snippets, or at least get the namespace?
I am modernizing a lot of VB.NET code to CSharp and I need to convert dozens of dialogs to conform with our new MVP standard. I'm trying to write snippets so I can more easily bang out the boiler ...
0
votes
0
answers
14
views
How to add custom user snippets like VSCode
I'm a fresh developer on Godot and trying to understand how to add custom user snippets into system like VSCode's user snippets.
What I'm trying to do is basicly saving a string with changable part (#-...
0
votes
0
answers
7
views
Modify TM_FILENAME_BASE in VSCode Snippets
I want to modify the $TM_FILENAME_BASE to generate a code snippet. As an example, I have a file that is called new_animals.py
This is my actual snippet
{
"Create Python": {
"...
0
votes
0
answers
13
views
Automatically Upscale all uploaded images in Wordpress and Keeping Aspect Ratio
I Had some trouble recently trying to automatically upscale (resize) all small uploaded images to my wordpress website, i tried many plugins but i found only the opposite (Bigger to small for ...
-1
votes
0
answers
39
views
Wordpress: Trigger a PHP Function in code snippet from front end
Newbie to Wordpress here... I'm trying to get some input from the user and simply email it back to them. I understand the differences between Javascript (client), PHP (server) and AJAX, but have never ...
0
votes
0
answers
34
views
Login without password for Wordpress 6.3
I have snippet below to login on wp-login page without password. I only need to know user login and I don’t need to input anything in password field. This sippet worked fine up to 6.2.2 WP version, ...
0
votes
0
answers
25
views
Workaround: Access variables of a liquid snippet rendered using the render tag
It's not possible to directly access variables from a rendered snippet ({% render 'snippet' %}). I've found this workaround, and it seems to work. Can somebody confirm this? Are there any drawbacks?
...
0
votes
1
answer
37
views
Is there a way to generate table aliases in TSQL statements using SQL snippets in Azure Data Studio?
In a user snippets the following work,
SELECT * FROM ${1:TableName} as ${2|a,b,c,d,e,f|}
but it only presents you with a list of the 6 letters ( a to f) for an alias like this:
SELECT * FROM ...
1
vote
1
answer
55
views
how can i make a code snippet in vscode / Ultisnips(vim) that can have variable number of arguments (tab triggers) like this:
if i type input5, then it produces code like:
cin >> $1 >> $2 >> $3 >> $4 >> $5;$0
and if i type input2, then it produces code like:
cin >> $1 >> $2;$0
...
0
votes
1
answer
54
views
VS Code suggests a code snippet that is not listed with the "insert snippets" command. Where/how is it defined?
when I type if, there's a snippet suggestion as below:
But I can't find this snippet by insert snippets command:
it shows nothing:
I just wonder why and the content of the if snippet ain't what I ...
0
votes
1
answer
29
views
Send Woocommerce registration confirmation email when administrator register a new Woocommerce client
I'm trying to create a snippet that send the woocommerce registration confirmation email to the new woocommerce clients that are registered by the administrator so they can see their password or reset ...
0
votes
0
answers
78
views
Elementor Pro Forms Validation for Zipcode
I'm using a simple form using Elementor Pro Forms. I'd like to filter out spam by only allowing zip codes starting with 91 or 92. Is there a code snippet I can add to help me do this?
I found this on ...
0
votes
1
answer
37
views
Visual Studio 2022 Snippets work incorrectly for C# [duplicate]
I wrote a snippet , but c# snippet code writes half of the.
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/...
0
votes
0
answers
89
views
Syntax highlighted code in Markdown dropdown
I'm writing a README file for my GitHub repository using Markdown. At one point in the README file, I have C# code that the user may copy-paste. This code is long—54 lines, to be exact—and I don't ...
0
votes
0
answers
17
views
How To Get only the children of the parent category by parent id that show in shop in wordpress
I have 3 parent categories: one, two, and three. Inside the 'one' category, for example, there are 'first-one', 'second-one', 'third-one', and so on. The same goes for the 'two' category, where we ...
0
votes
0
answers
8
views
Add colour preview to Visual Studio code snippet extension
I recently developed a Visual Studio Code extension using the Yo Code generator and selected the New Snippets Extension template. My extension provides several useful code snippets for my CSS Library ...
0
votes
1
answer
38
views
replace h2 with h1 in an Elementor Pro "archive products" widget
I would like to change all the product titles on this page (https://alessandramilano.eu/all-shoes/) from H2 to H1. How can I do?
I have tried different codes but I can't get to the solution. Do I have ...
0
votes
0
answers
16
views
How to create an embed that allows switching between multiple code snippets via a button
I wish to create embeds in notion to manage and share my code snippets.
However, some code snippets serve the same purpose. For example, a sorting algorithm can be written in multiple programming ...
0
votes
2
answers
19
views
Why doesn't VSCODE let auto-completion happen within the tab stops of a snippet?
I love snippets and use dozens all the time, but am constantly frustrated by the fact I cannot figure out how to make VSCODE guess what I am typing while I am typing inside a tab stop of a snippet.
If ...
0
votes
1
answer
17
views
What is the difference between List and Collection in Snapi language?
I have two queries in snapi language:
let hello = List.Build(1,2,3) in hello
and
let hello = Collection.Build(1,2,3) in hello
They return the same result.
I run the queries but I don't see any ...
0
votes
0
answers
36
views
Woocommerce - Percentage off on the sale badge php snippet does not work in the home page
On my website choupetteland.fr I put a php snippet (see below) found on the WP Simple Hacks Youtube channel for showing percentage off on the sale badge. It works well in my category and product pages ...
0
votes
0
answers
33
views
Trying to install an initalize HTML snippet within a PHP variable
I'm trying to get a snippet to initialize on every page but it requires a PHP variable to pull in the correct information. How would I write the code - I currently have the following but it will not ...
0
votes
0
answers
13
views
Transform Property Name to lowercase
I wrote a snippet for Visual Studio 22 with the following content:
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/...
4
votes
1
answer
185
views
Switch case autocomplete not working in Android Studio after dart3 migration
In the past I successfully used switch auto completing for creating all the missing cases. But after migrating to the dart 3 that's feature not work yet. All what I see - the error message about ...
0
votes
0
answers
37
views
How can I set Minimum & Maximum items quantity per order based on categories Wooccomerce using PHP
I have this issue: I have 4 categories, but I want that users can purchase min & a max of 3 items in a total of 3 of these categories. And, for the other category, they can only add 1 item per ...
0
votes
0
answers
195
views
How can I make a code section in the Azure DevOps comment collapsable?
How can I make a code section in the Azure DevOps comment collapsable?
I need this for the cases when I paste a lot of code or JSON. I tried two things.
First, I tried just clicking the Code button in ...
0
votes
2
answers
127
views
Why does sysout code snippet stop working in VS code after a few seconds?
enter image description here
I am trying to use Java in VS code. I am having problems with code completion snippets. I have the Language Support for Java(TM) by Red Hat extension installed (along with ...
0
votes
0
answers
33
views
How to locate and debug WordPress Snippet
In my WordPress project i have a snippet, configured to "Run snippet everywhere".
But it seems the code of my snippet isn't working correctly, so i wish i could debug it.
My snippet is a PHP ...
2
votes
0
answers
47
views
How Can I Make Kate Properly Indent Snippets with Multiple Lines
I enjoy using Kate snippets for quick Python scripts, but I'm having a hard time getting them to properly inherit or detect indentation levels after the first line. Consider the following snippet:
...
1
vote
3
answers
74
views
How can I create VS Code snippets that consume pre-existing text placed before the snippet prefix and use it in the snippet body?
I want to make snippet for console.log(variable) but instead to have prefix I want to make this with "suffix". Here's an example:
var name = "Marco";
var car = "Volvo";
...
0
votes
0
answers
37
views
Align Line number to Code snippet Vite React js
I'm new in Vite react js also with tailwind and its hard to deal with css to design my web app. In these problem, I'm trying to create a code snippet with a line number but it's hard to align these ...
0
votes
0
answers
141
views
In Visual Studio 2022, how can I change the null check template?
I frequently apply null checks to my parameters when developing in C# (like any good developer should!).
Because I can be lazy, I'd prefer to let Visual Studio add these for me, which it can.
However, ...
0
votes
0
answers
76
views
Wordpress homepage with text displayed from php code snippets not updating in real time
I have a wordpress website which uses two php code snippets on the homepage that reference a database and echo data based on the database entries. I'm using the 'Code Snippets' plugin to store the ...
1
vote
1
answer
33
views
Project/Solution Level Code Snippets for Visual Studio
I'm able to create snippets for visual studio in my documents file. But I'd like some snippets to be distributed to the rest of my team via source control, so some way of including a snippet with a ...
1
vote
1
answer
45
views
WooCommerce discount for unlogged users based on if a field has any input add 10% discount
I would like to give 10% discount for companies (B2B) but I don't want to give discount for individual person (B2C). The only way to check if somebody (not logged in) is an individual person or a ...
0
votes
0
answers
117
views
How to fix WordPress Fetch API 404 error?
can you give me a hint?
When using JS Fetch API and $.post in the code snippet plugin in WordPress environment I am able to post data to PHP file and get what I need returned.
But the problem is it ...
0
votes
0
answers
24
views
Adding number to custom field in Ultimate Member after purchase with WooCommerce
I am trying to activate a code every time that a person purchased a product on my website. I am not very familiar with the coding in php in WordPress. I have used Pods to create custom user fields. I ...
0
votes
1
answer
79
views
How can I customize a suffix snippet, replacing the variable in VS Code?
I'm developing my Java project with VS Code when I find some powerful snippets:
suffix code snippets
After I type a variable name and type .sysout, .cast and so on, the snippet suggestion pop out. ...
0
votes
0
answers
34
views
WordPress redirection code not working as expected
I'm having trouble getting a WordPress redirection code to work as expected and would appreciate any advice you can offer.
Here's what I'm trying to do: I have several domain names that are redirected ...
0
votes
1
answer
31
views
emmet custom snippets with variables
I need generate my custom tag "django template tag"
I want to create correct tag for snippet
after
bdlock{foo}
get
{% block foo %}
{% endblock content %}
I have that
{
"html&...
0
votes
0
answers
81
views
coc-snippets doesn't complete functions
I'm trying to use coc-snippets for neovim, but the snippets for functions don't work as intended.
It Should be completed to: function(param1, param2)
But it only completes to: function
Here's my init....
0
votes
0
answers
25
views
Eclipse creates snippet package when pasting code into Explorer
When pasting a the code of a class into the Project Explorer of Eclipse, the code is pasted into the selected source Folder inside the correct package.
But when there is a comment above the package ...
0
votes
0
answers
56
views
How to make a parent page for a custom taxonomy in woocommerce
I am using Woof product filter plugin and want to add a new taxonomy. Right now I have it set up with categories (type of products), brands using Perfect Brands for Woocommerce (assigns custom "...