Questions tagged [code]
The code tag has no usage guidance.
305
questions
129
votes
4
answers
238k
views
How to display SQL query that ran in query?
I have come across a function before that displayed the exact SQL code that was used.
In a loop for example, but can't remember.
Can anybody tell me that function?
65
votes
7
answers
19k
views
Best collection of code for your .htaccess file [closed]
We have the Best Collection of Code for your functions.php file thread, so I thought that it might be useful to create a thread for our .htaccess files.
AND PLEASE REMEMBER TO ADD ANY OF YOUR OWN ...
18
votes
1
answer
85k
views
What is the meaning of %s, %1$s etc.? [closed]
From a Q&A Thread I've came to meet with some old things, but I'm afraid, I found myself in a condition that, I still don't know the meaning of them and don't know why to use them.
%1$s - (found ...
16
votes
5
answers
45k
views
Upload Multiple Files With media_handle_upload
I have a WordPress form plugin and I use media_handle_upload to upload the files and get there ids directly and attached its ids to the post as a meta date, I used the following to did that:
The HTML ...
11
votes
2
answers
9k
views
Include WP_Query in my own PHP file?
I want to write a cronjob for myself. But I need to get access to WP_Query and the permissions to delete posts etc.
My question now is, how can I include the WP_Query function to my own PHP file and ...
8
votes
2
answers
469
views
WordPress Internal @ Mentions
I'm looking for a way to link to author pages within one WordPress install simply by putting the @ symbol in front of a person's username in a post.... just like on twitter.
Example:
If the username ...
8
votes
2
answers
5k
views
Return $post_id when DOING_AUTOSAVE?
I see the following pattern over and over, on this site and on other places:
add_action( 'save_post', 'wpse14169_save_post' );
function wpse14169_save_post( $post_id )
{
if ( defined( '...
8
votes
2
answers
858
views
How to get a variable number of posts per post type on the main loop?
I'm looking for a way to balance the content at the homepage of my blog:
the blog has a few post types like Poscasts, Videos and Blog and I'd like to have let's say 10 Posts on the homepage, but I'd ...
7
votes
4
answers
27k
views
What is this code in my theme's functions.php? if (isset($_REQUEST['action']) && isset($_REQUEST['password'])
This code appears in my theme's functions.php, also in child theme's. I've deleted it for two times but it comes back. What is it?
if ( isset( $_REQUEST['action'] ) && isset( $_REQUEST['...
6
votes
5
answers
12k
views
What theme is good for posting code? [closed]
I have my blog hosted at www.alphaot.com and I guess it's good enough. But problems arise when the lines of code get longer than 30 characters. The lines just wrap and get icky or something they even ...
5
votes
2
answers
2k
views
Create custom [sourcecode] shortcode, the right way?
What I want to do
Sharing code in posts on WordPress is quite a pain with all the HTML escaping to take care of. So, I plan to enclose code in posts within a custom shortcode called [sourcecode], as ...
5
votes
1
answer
2k
views
how to group custom post types
I wanted to know do i group my custom post types to appear together in a group in the wordpress back end menu bar like this below in the picture what code do i have to use in my functions.php so that ...
4
votes
2
answers
4k
views
How to create a custom button for the visual editor that adds 4 non-breaking spaces? (plugin or simple code)
To Wordpress' visual editor (TinyMCE), I would like to add a button that adds four non-breaking spaces when clicked, like this:
I found some plugins that add ...
4
votes
2
answers
231
views
How do i structure my theme folder to avoid one huge list of files
When working with a worpress site with lots of custom post types and lots of page templates, my theme folder is looking messy. What are the accepted best practices to organise code files in WordPress?
...
3
votes
3
answers
2k
views
Editing Source Code in Wordpress
I am a senior in a college computer science program, and therefore have a decent knowledge of code and several languages. However, I am doing a summer internship type program, and the company I am ...
3
votes
2
answers
1k
views
Completely disable RSS feeds on WP 5.5.2 and show a 404 page instead of die();
I'd like to completely disable RSS feeds on my WP website. Can someone please guide me on how to throw a 404.php page and set the headers to 404, when someone types in https://example.com/feed/
here ...
3
votes
2
answers
1k
views
Has anyone tried putting PHP ActiveRecord on Wordpress?
I have worked with Ruby on Rails and I was looking for some code that did something close to the wonderfull RoR's ActiveRecord.
I stepped by this site. Its PHP-ActiveRecord!
I found it amazing, and ...
3
votes
1
answer
3k
views
API integration with WordPress
I'm trying to integrate a 3rd party API with WordPress. I fear this is above my head. I was this code but I'm not exactly sure how to make is work in WordPress. Is it possible?
$ch = curl_init();
...
3
votes
0
answers
38
views
Date/time limitation of posts where function must be executed
I have this piece of function in my functions.php file:
function user_content_replace($content) {
$sentences_per_paragraph = 3; // settings
$pattern = '~(?<=[.?!…])\s+~'; // some punctuation and ...
3
votes
2
answers
899
views
Including Angle Brackets In Pre Sections
I am attempting to post some java code between pre tags but the angel brackets get removed. For example:
private HashMap<String, HashMap<String, Integer>> featureCounts;
becomes
...
2
votes
1
answer
2k
views
Open posts in editor in the 'Text' mode by default
I have a few posts where there are some code segments. When I try to make small edits in the post, it opens in the 'Visual' mode and all the non-alphanumeric characters (e.g. >) are converted to ...
2
votes
3
answers
1k
views
Pinterest Integration Using functions.php
I use a theme to build an portfolio.
I´d like to add an pinterest "pin-it button" into the fuctions.php:
Facebook, Google+ an Twitter were done, just the pinterest won´t work.
Can´t found the the ...
2
votes
2
answers
2k
views
Notice: Undefined property: wpdb::$current_post What can be wrong?
I'm working on a WordPress site and I use the following code to show posts in two columns on archive and category pages:
<div id="post-<?php the_ID(); ?>" <?php post_class( 0 === ++$...
2
votes
1
answer
1k
views
Which theme foundry has clean coded themes, where code is poetry [closed]
I'm looking to find a theme foundry (ie. woothemes, elegant themes) that has themes that are very well coded; where "code is poetry". To be more precise, I'm looking for themes coded in "the wordpress ...
2
votes
1
answer
1k
views
Can I run custom php on specific pages in wordpress?
I'm making a wp site as a new frontend to an in house system that I designed a while back.
I want to be able to run custom php for grabbing different bits and peices of stuff from my database (mysql) ...
2
votes
1
answer
134
views
Admin Notices coding standard issue
I am having a bit of an issue right now with the VIP coding standards. I am trying to print out an admin notice as follows:
add_action( 'admin_notices', function() {
$class = 'notice notice-...
2
votes
1
answer
1k
views
How To Add Perfect Apostrophe And Quotation Mark In WordPress Posts?
I have a blog at www.exeideas.com where I am sharing codes snippet too. I am new to WordPress and migrated from Blogger. So now my all codes shared in posts stop working. When I check my codes then ...
2
votes
1
answer
5k
views
Successful or Error Message after running mysql code in functions.php
Just for this article, suppose there is a code that I want to run on my WordPress' functions.php file. It's a code to delete mysql table on my database. For example, here's the code:
$wpdb->query( ...
2
votes
1
answer
2k
views
Adding custom styles to dropdown in editor
is it possible to add a custom style to the dropdown in the classic WordPress editor, say a div with the class of "fancywords"?
2
votes
1
answer
2k
views
Can I view my own wordpress php source code on my hosted web server?
OK so everyone must ask how to see the php source code sometime and I asked it to myself too.
and yes I know it that the php is processed by the server before outputting it to web page, so with that ...
2
votes
1
answer
3k
views
Beautify WordPress HTML output without any plugins
Is there a simple (and without plugin) way to clean up the WordPress output of HTML? With a beautiful indentation of the code?
I don't understand why, but my HTML output isn't perfect and it makes me ...
2
votes
1
answer
69
views
Where to save common libraries?
I have a multiple-site WordPress install. I have decided to centralize as many of my libraries as possible into one spot, for obvious organizational reasons, and in order to reduce bloating. Many of ...
2
votes
2
answers
1k
views
Replacing the default content created while the site creation
How do you replace the default title for first comment?
Mr WordPress on Hello world!
I could not able to locate this in theme's comments.php file
I want to edit the title 'Mr wordpress on Hello ...
2
votes
1
answer
6k
views
How to implement Google reCaptcha without installing a plugin?
Wordpress noob here wondering how to include reCaptcha authentication in my login without a plugin?
So far I have added the captcha div into the login using a hook:
add_action('login_form','...
2
votes
1
answer
2k
views
Adminbar Missing "Edit Page"
I'm encountering a problem that involves that my Admin bar doesn't show the "Edit Page" on pages I visit on my site. Instead for some odd reason it show "Edit Category" instead on supposed page.
Does ...
2
votes
1
answer
3k
views
How do i get (unique) page name?
Like from the page of http://localhost/wordpress/about_us/ how do i get only the "about_us" ?
Thanks
2
votes
1
answer
4k
views
Connect Second Database to Wordpress
I am trying to connect a second database to my wordpress site so that I may ask for data from it and display it in a table on my site. I have tried multiple ways of doing so. I have tried to use php ...
2
votes
1
answer
68
views
Don't understand why theming is so strange and twisted [closed]
What I'm asking you here is not a technical question, but more a philosophical one. I firstly started developing themes for a small new cms that I also contributed on github that has a great potential,...
2
votes
0
answers
1k
views
source code: WP_INSTALLING vs. WP_SETUP_CONFIG in setup-config.php
I am trying to make sense of the wordpress installation process.
The file setup-config.php under wp-admin has the following.
I want to know what the difference is between these two variables,
why both ...
2
votes
1
answer
548
views
Sublime Video: Playlist which gets all attached videos
I searched a way to automatically load all attached videos in a custom post type as SublimeVideo playlist. After some time I got it working and here I'll share the code with everyone who is interested ...
1
vote
2
answers
16k
views
Wordpress redirect all 404 pages to the Homepage
I want to redirect all 404 error pages on my WordPress site to the homepage, or to a specific page.
Any advice?
1
vote
2
answers
1k
views
VERY new to coding - keep breaking site trying to add to functions.php
I really appreciate everyone on this site who takes the time to answer questions here. I've learned a good deal already reading, but am sure I could learn even more if I could get past at least one ...
1
vote
1
answer
951
views
Gist shortcode is not working
I freshly installed a brand new Wordpress for testing purpose as I am intending to refresh my current website. One of the requirement I have is to be able to embed code from Gist. Following the ...
1
vote
3
answers
1k
views
Code Friendly Block Quotes
I have a self-hosted Wordpress Blog (located at http://www.dougmolineux.com/wp if you're interesed :)
I put a lot of Code Snippets on there, because I'm a programmer. How do I make these "snippets" ...
1
vote
2
answers
28k
views
How to display posts of specific category using a custom Query in WordPress?
Hi I want to display a specific category from a custom query in WordPress. My code works fine and it gets the latest 4 posts, but what I want now is to retrieve a specific category. My code is below ...
1
vote
2
answers
606
views
How to fix a “globals” issue to avoid a rejected theme?
I submit a WordPress theme for Themeforest and one of the reasons for rejection was as follows:
Globals should always be within a function or a class and should be used restrictively & only if ...
1
vote
2
answers
156
views
Cannot find the code for "Edit This" link in posts in a specific theme
I cannot for the life of me find the code for this particular item:
Usually in other themes there's the link "Edit" on the front page and post page to directly go to edit the post in admin panel. ...
1
vote
1
answer
1k
views
Remove line breaks from <code>?
This code form HTML editor:
<code>[shortcode]
[bar]foo[/bar]
[bar]foo[/bar]
[bar]foo&...
1
vote
3
answers
962
views
The custom logo, site title, and description doesn't appear at the same time
The problem I'm having is the custom logo, site title, and description won't appear at the same time. In image 1 below, you can see that with no custom logo, the site title, and description appears ...
1
vote
1
answer
614
views
How to make this WP_Query run faster on a WordPress website?
This code is part of a custom WordPress homepage that shows the 7 most recent posts using WP_Query, and the first post has a custom html structurer, while the rest has another html structure.
Then ...