question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
I'm struggling to get a nb_NO version of the wordpress admin interface. Here's what I've done so far: Installed latest wordpress from wordpress.org Moved installation from root to wp/ - site working fine Edited wp-config.php to define('WPLANG', 'nb_NO'); Went to wp-admin and clicked "Re-install now" on the 3.5.1–nb_NO ...
The problem was that I had changed the 'WP_CONTENT_DIR' directory, and Wordpress did not have writing permission to the new content folder, so it couldn't create the 'WP_CONTENT_DIR'/languages folder. After creating the languages folder in my new WP_CONTENT_DIR directory Wordpress did the language upgrade successfully.
Wordpress admin not changing language
wordpress
I'm writing up unit tests for my plugin and I need a logged in user to test, but I can't find the admin password anywhere. Does anybody know what the default admin password is? I'm extending the <code> WP_UnitTestCase </code> and taking the tests from https://unit-tests.svn.wordpress.org/trunk . My code at the moment: ...
The password is … <code> password </code> . You can see that in <code> includes/install.php </code> : <code> wp_install( WP_TESTS_TITLE, 'admin', WP_TESTS_EMAIL, true, null, 'password' ); </code> The last parameter is the admin password.
unit testing admin password
wordpress
I have a cron job that alerts me to modified files on a couple of WordPress installs. Two of them alerted me tonight to the creation of apparently empty folders like <code> /home/foo/public_html/wp-content/uploads/2013/05 </code> Is there a scheduled job in WordPress to create the next month's upload directory on the l...
I believe by default these folders are created by user interaction, however, it's possible that a plugin may be calling a function to create these monthly upload folders. Note that using this function will create a subfolder in your Uploads folder corresponding to the queried month (or current month, if no $time argume...
Are uploads directories created on a schedule?
wordpress
Hi I'm having problems with the <code> the_title </code> filter here's the code that I have: <code> function zen_title_filter($title){ if(is_singular()){ if(!empty($_GET['asin'])){ if($title == 'Product Details Page' || $title == 'Compare Products Page'){ $title = zen_get_titles(); } } } return $title; } add_filter('th...
Since you're generating things on the fly, we can use a global flag to let us know when we want the title applied. <code> add_filter('the_content', function($content){ if(is_page('compare')){ global $asin_doing_template; // mark that we're doing a template $asin_doing_template = true; $asin = esc_attr($_GET['asin']); $...
Adding filter to the title without affecting the menu title
wordpress
I would like to add an extra feature to one of the default widgets so that the user can choose from the select-field to either align the widget to the left, center or to the right. How would I be able to achieve this without tampering with any of the files outside of my themes directory?
The default widgets do not offer any hooks for that. You have to replace the default widget and add your field to the new class. The other option would be using JavaScript to insert the field, and a filter for <code> 'update_option_widget_' . $widget-&gt;id_base </code> to save the value. I think the separate class is ...
Add a select-option to the default widgets
wordpress
I am try to show different menus for login and logout user. stackexchange-url ("Here") is perfect solution to do this and also work on Twenty eleven theme. But when I try to add this code to my woo theme's defination (in header.php) I got this error <code> Parse error: syntax error, unexpected '}' in C:\xampp-portable\...
I placed your code in a line number editor to find line <code> 63 </code> . I have marked the line with the extra <code> } </code> (well it's in line <code> 64 </code> in my editor) This is a <code> PHP </code> error you got. Try to remove this line.
Show different menus for login / logout user
wordpress
I have a wordpress setup that I use for clients with around 30 or so child themes that they can choose from. Each child theme has it's own functions.php file currently. Is it possible to setup just one child functions.php and call it from all the separate child themes? My reason for wanting this functionality is I find...
Well, I'd say that you need a custom plugin. All the rationale is in this Q&amp;A: stackexchange-url ("Where to put my code: plugin or functions.php?") Also related: stackexchange-url ("Where do I put the code snippets I found here or somewhere else on the web?") Create a Functionality Plugin Instead of Using Functions...
One Child Functions.php for Multiple Child Themes
wordpress
I'm trying to add an area on the admin bar that will display user Profile Image, User Name, User Email, User role, and links to Edit Profile and signout. The way in which I would like it to display is Steve Jackson - stevejack@yahoo.com Author Edit Profile &lt;&lt;&lt; "Link" Signout &lt;&lt;&lt; "Link" With the user i...
I think you need to use "global $current_user;" in your function to get the details of $current_user and global $wp_admin_bar; for admin bar. This is how I managed to get the role of the current user and change the URL from admin depending on role (It doesn't solve your issue, but maybe you find it helpful) <code> func...
Custom Div with links on Admin Bar
wordpress
In the script below, I need to get the URL path to the "medium" size image in the "data-responsive" attribute. Its currently returning the thumbnail size. <code> the_post_thumbnail("thumbnail", array( 'itemprop' =&gt; 'image', 'class' =&gt; 'alignleft', 'style' =&gt; 'margin:5px 15px 10px 0;', 'data-responsive' =&gt; w...
<code> wp_get_attachment_thumb_url() </code> does not accept size as argument. You might be looking for <code> wp_get_attachment_image_src() </code> , but I am not sure on top of my head - too many functions in that corner.
the_post_thumbnail() get the URL to the "medium" sized image
wordpress
I am wondering how the search go through by defining 's' parameter in WP_Query. For example if I have a post assigned to "East" term in taxonomy "Direction", the post didn't mention any "East" or "Direction" word in the post content or title. When I define the 's' value as "east" (no other parameter defined) in the WP_...
WP search is rather simplistic. After some processing on search query, it adds condition to SQL query looking for <code> LIKE </code> (contains) match in title or post content. So natively assigned taxonomies are not searched. So you will either have to use additional code (or third party plugin) or use third party sea...
How does Show Posts based on a keyword search work in WP_Query
wordpress
I am not sure if it is much different for any page but I am wondering how to remove a metabox from the appearance> menu page without having to go into the wordpress core files and remove it. Is there something I can do to override it so it doesn't appear both on the page and on the screen options menu?
By inspecting the file <code> /wp-admin/nav-menus.php </code> we can see that these meta-boxes: are rendered with: <code> &lt;?php do_meta_boxes( 'nav-menus', 'side', null ); ?&gt; </code> The file <code> /wp-admin/includes/nav-menu.php </code> contains the corresponding <code> add_meta_box() </code> calls and from tha...
How to remove a metabox from menu editor page?
wordpress
How to add qtranslate-support for custom post type? Just saving text with tags OR add flag switcher. My Custom Post Type field: <code> add_meta_box('project_rolesid', 'Roles box', 'project_roles', 'portfolio', 'normal'); &lt;textarea id="portfolio_project_roles" cols="80" rows="7" name="portfolio_project_roles"&gt;'.$r...
Using tags is pretty straightforward. All data in qTranslate is stored between special <code> &lt;!--:lang--&gt;content&lt;!--:--&gt; </code> tags, wherein <code> lang </code> is the code for the language, like <code> en </code> , <code> ru </code> , <code> de </code> , etc. The post edit UI is altered via qTranslate's...
QTranslate for Custom Post Type
wordpress
When would it be appropriate to use the settings API, and when would it be better to use the theme customizer? Having Googled around all morning, I haven't been able to find any well considered and recent guidance on this matter. While it's still early to say, I feel that the theme customizer is a suggestive first step...
The premise of the question is flawed. The Customizer API is not an options API, but rather an options preview API. The Customizer API relies on either the Settings API or the Theme Mods API to register controls for existing settings added via either of the two APIs. The Customizer does not - and cannot - define/regist...
Settings API vs Theme Customizer
wordpress
I thought Wordpress post IDs were only unique within each post type, so that the first instance of each post type would have an ID of 1 and they would count up from there. In order to get a specific instance of a custom post type, you would have to designate that post type in the query. But according to stackexchange-u...
All post types are stored in the same <code> posts </code> table, so they have to use different post IDs. That was always the case, since the the post type <code> page </code> was introduced 2005 with version 1.5 .
Are Post IDs Unique Across all Post Types?
wordpress
For example, I have WooCommerce products that have taxonomies: brand (e.g. Converse, adidas, D&amp;G) (taxonomy id: product_brand) category (e.g. Boots, Sneakers, Sandals, Heels) (taxonomy id: product_cat) Of course, not every brand includes all categories. I need to list the categories by brand. (something similar to ...
To get a list of all terms of taxonomy X whose posts are associated to terms from taxonomy Y too, we have to: Get all term IDs for both taxonomies Create a tax query to fetch all posts, because we don’t want to show empty term archives. Format the result in a hierarchical list. Let’s go! Getting the term IDs is simple:...
Combine two taxonomies in a hierarchical tree
wordpress
I'm trying to figure out some kind of mechanism to load plugins on demand, depending on the page url, to improve performance. My primary concern is that I have some admin-ajax.php calls that are recurring while the user is active on the page. I tried profiling these calls, and discovered that the majority of plugins lo...
Filter <code> option_active_plugins </code> . You can change the result of <code> get_option() </code> here without actually changing the database. <code> if ( defined( 'DOING_AJAX' ) &amp;&amp; DOING_AJAX ) add_filter( 'option_active_plugins', 'disable_plugins_temporary' ); function disable_plugins_temporary( $plugins...
Strategies to implement selective loading of plugins
wordpress
i am trying to get the User_ID outside of wordpress. I have a rating plugin and it needs the current user id, to cast votes. However it seems that something is going wrong. This is the part of the code i am using in my functions.php file: <code> function get_userid(){ $user = get_current_user_id( ); //i can correctly e...
AJAX requests (which you imply you are using but do not explain/demonstrate) do not load your active theme, which is where <code> functions.php </code> resides (unless you were referring to a <code> functions.php </code> file that you created in your plugin's directory). As such, your <code> call_user_func() </code> is...
Get User_id outside wordpress,
wordpress
Installed a plugin that allows the re-ordering of posts from any post type / category / tag using a drag/drop interface. After some time of using, my post order went haywire and new posts began to appear in a jumbled order. The plugin's native reset button resolved this, but the old posts are still jumbled (only for tw...
This piece of mySQL code should do the trick. Go into PHPmyAdmin, click the SQL tab and paste this code: <code> UPDATE wp_posts SET menu_order = 0 WHERE post_type = 'my_post_type'; </code> This should set <code> menu_order </code> for all posts of the post type of your choice to 0.
Resetting menu_order to 0 for posts in PHPmyAdmin?
wordpress
I'm finding the documentation on coding WP stuff to be very lacking and can't figure out which files I need to include in my PHP script to get a bare minimum working code environment? Example: I want to call <code> wp_insert_user() </code> to add a user to my site. How do I know which files in <code> wp-includes/ </cod...
You want to include <code> wp-load.php </code> or <code> wp-blog-header.php </code> not <code> wp-settings.php </code> or <code> wp-config.php </code> directly. If you look at the code in <code> wp-load.php </code> you will see why . <code> wp-load.php </code> looks for <code> wp-config.php </code> in several different...
Bare minimum to include in PHP file to use WP functions?
wordpress
I am trying to figure out how I can pre-load a theme customizer image control with images I have selected. Is their a way to point the control to a directory so they automatically show up in the uploaded list? So the user can select an image from the list if they like it. If anyone could explain this I would greatly ap...
Our journey starts <code> here </code> with the <code> WP_Customize_Background_Image_Control </code> class, which is a <code> WP_Customize_Image_Control </code> . I'd imagine offering these built-in backgrounds in a new tab alongside the existing <code> Upload New </code> and <code> Uploaded </code> tabs. There are at ...
How to add default images into theme customizer image control?
wordpress
I want to remove "Search for" text from search form in TwentyTwelve, to wrap in in a div for styling, and probably to play with php a bit – and I'd appreciate some advice on how to do that best. My "sub-questions within a question": 1) Where is the main search function is located? 2) Should I create a separate custom f...
Modify the <code> searchform.php </code> , or create one in a child theme (recommended), and you should be able to modify the form all you want. This is the file that <code> get_search_form </code> looks for and is the file used by the default search widget, though it is not listed in the Template Hierarchy . Reference...
Modify search function in WordPress (TwentyTwelve)
wordpress
How can I access <code> $_POST </code> data after a page redirect? I guess there is some way to tell WordPress to pass all <code> $_POST </code> data to the redirected address, like it does with <code> $_GET </code> data, using Rewrite Rules, but how?
Redirects are GET requests usually, and the browser doesn’t send the POST data for those. That’s not something WordPress can change. You could create a session, or – better – process the POST data first, then redirect. In your plugin, you could do: <code> add_action( 'plugins_loaded', 'process_post_data', 0 ); function...
Access $_POST data after redirect
wordpress
Is there a known issue that would prevent the "Feedbacks" menu item from showing? I have two wordpress installs, one has the menu item the other doesn't. They both have the same plugins, theme, and scripts.
To get the <code> Feedbacks </code> admin menu with the Jetpack plugin installed one has to make sure the <code> Contact Form </code> is activated through the Jetpack setup page <code> /wp-admin/admin.php?page=jetpack </code> :
Why Jetpack is missing the "Feedbacks" menu item?
wordpress
I'm using the following code to get a list of all the pages that are children of my project page and display them in a Recent Projects section of my template's footer element. I've noticed that the <code> get_page_children() </code> method returns everything about that page - <code> post_author </code> , <code> post_da...
You can just return the IDs, then get each title by the respective ID. And to restrict the query to four posts only, you can use <code> posts_per_page </code> . I modified and optimized your above code a bit, so here it is: <code> &lt;h3&gt;Recent Projects&lt;/h3&gt; &lt;ul class="footer-list"&gt;&lt;?php $projects_pag...
get_page_children() return only titles
wordpress
To display the most popular posts based on page views I am using this code ( source ): <code> &lt;?php query_posts('meta_key=post_views_count&amp;orderby=meta_value_num&amp;order=DESC'); if (have_posts()) : while (have_posts()) : the_post(); ?&gt; &lt;li&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_t...
I've done something in the past using custom fields. Maybe this can get you going in the right direction? This is done directly after the <code> &lt;?php while ( have_posts() ) : the_post(); ?&gt; </code> <code> &lt;?php $currentdate = date("Ymd"); $expirationdate = genesis_get_custom_field('_racedate'); $expirestring ...
Restrict query_posts by Date?
wordpress
PROBLEM: I'am trying to prevent execution of default WordPress query for custom category template. I have found a possible solution, but looks like it preventing execution of all post queries: <code> function _cancel_query( $query ) { if ( !is_admin() &amp;&amp; !is_feed() &amp;&amp; is_search() ) { $query = false; } r...
Completely canceling main query is pretty much high level madness, that involves subclassing <code> wp </code> class. I would: Hook into <code> pre_get_posts </code> with <code> is_main_query() </code> check Run featured query (still inside hook) and stash results somewhere Use those results to set excluded posts on ma...
How to prevent execution of default query, while preserving ability to use WP_Query in template?
wordpress
I am trying to make a personal plugin that does specific things based on what is loaded. In this example, in my action method I want to perform one function if the currently loading page is using the <code> template-blog.php </code> template, if it's a single blog post (loading <code> single.php </code> do a second fun...
Using <code> body_class() </code> on the body tag would probably be the easiest way to tell which template is in use. <code> &lt;body &lt;?php body_class(); ?&gt;&gt; </code> Depending on which page you are on, it will output similar to this <code> &lt;body class="page page-id-10 page-template-default logged-in"&gt; </...
Determine which template-{slug}.php is being loaded
wordpress
For some reason the PrettyPhoto script that WooCommerce is now using is adding #prettyPhoto to the end of URL's once it's been opened in that page. See here for an example Also, when you close the lightbox down it takes 2 or 3 clicks of the back button to get back to where you were previously. Anyone have any idea why?
That is a … feature of this script, called deeplinking . It should be fixed already , maybe you missed an update? As you can see in that commit , you can disable it by editing <code> assets/js/prettyPhoto/jquery.prettyPhoto.init.js </code> . Add <code> deeplinking: false </code> … to all calls of <code> prettyPhoto({})...
WooCommerce - PrettyPhoto appending URL with #prettyPhoto
wordpress
I'm wondering, given this code: <code> add_shortcode( $tag , $func ); </code> Is there a hook I can use that will always be called AFTER the last time <code> $func </code> was called, but soon enough, so I can still call <code> wp_localize_script() </code> ? WP Function referencres: add_shortcode , wp_localize_script
Not sure about the last time, but you can hijack every shortcode and either call <code> wp_localize_script() </code> here or register an action for <code> wp_footer </code> that runs earlier than the footer script handler. Let’s say, this is the original: <code> add_shortcode( 'foo', 'original_function' ); </code> Now ...
detect when shortcode ran for the last time
wordpress
Is there a way to write a php conditional in WordPress that says: <code> "If 'editor' is not filled out (i.e. empty), then, do some code..." </code> I know it's sort of a strange request but basically I have a portfolio set up where if I don't fill out the editor for a post (i.e. project), I don't want a certain link t...
I'm using something of the sorts for delivering some standard default text if the post content is empty. Give this a whirl: <code> &lt;?php if( $post-&gt;post_content != "" ) { //do something or show content } else { //do something else }?&gt; </code>
If 'editor' is empty, then
wordpress
On the admin add/edit post page, I have a new meta box with submit button. I want to submit them separately. For example if some one click on Publish / update button then it save all post content and when some one click on meta box submit button then it should save meta box fields in a new DB table. Code is attached. <...
IMO, it's much better to solve this with Ajax. Maybe it's possible the way you're proposing, but it seems a bit confusing from an User Experience perspective: two similar buttons that do different things. What if the user modifies the content and the custom fields, updates one and loses the other? Maybe the <code> save...
Is there a way to submit only meta box content in Post edit page
wordpress
I want to add a meta box to the menu page. More specifically I want to basically clone the pages or category meta box and have it load the items into the list from a meta key, instead of pages or categories. My theme is one page, so users create content for the front page with posts. When users make posts on my theme i...
The meta boxes for the Appearance-> Menus section are in <code> /wp-admin/includes/nav-menu.php </code> . The meta boxes for posts and pages are mostly in <code> /wp-admin/includes/meta-boxes.php </code> , if you need those.
Where can I find the code for the menu page meta boxes?
wordpress
I have a custom walker for a navigation menu on my website, and within it I have some custom CSS that I want to apply to each menu, however, I cannot simply echo it there because even though it works fine, it is invalid code according to W3 validator. The solution is to send that css code to the Head section, but I am ...
Call <code> wp_nav_menu() </code> before <code> wp_head() </code> is called, and store the result for later usage: <code> &lt;head&gt; &lt;?php $menu = wp_nav_menu( array( 'echo' =&gt; FALSE, 'theme_location' =&gt; 'primary', 'walker' =&gt; new Special_Walker ) ); wp_head(); ?&gt; &lt;/head&gt; &lt;body&gt; &lt;?php ec...
Add CSS to head depending on nav menu walker
wordpress
I built a custom theme, and in it, there is a 404.php page and a search.php page. Elsewhere in the template, I wanted to link to the search page directly. So, I used the get_search_template() function to get the search page link, which results in a link like this: http://example.org/search When I click the link, I get ...
Confusingly WordPress does not have a concept of a simply search page, it only has concept of search results page. The difference is critical because search without search query 404s as you are seeing. If you want dedicated search page you would have to implement it as custom one, see Codex > Creating a Search Page .
get_search_link() redirects to 404 template page
wordpress
after clicking on the reset password option in WP, we're getting this link <code> wp-login.php?action=rp&amp;key=[theKey]&amp;login=testing&gt; </code> instead of getting this can we alter it to something link to out custom page?
Try this <code> add_filter( 'lostpassword_url', 'lostpass_url_fix'); function lostpass_url_fix( $link ){ return 'http://example.com'; } </code> Just replace the example.com with any url you want
Alter the reset password link
wordpress
I've written a query that is supposed to return all attachments called "no-image" (is part of a function that handle images fallback when there isn't a featured image), the if I get some result, the function returns the first item. Here's the code: <code> function misamee_get_image_placeholder($size, $icon = false, $at...
There is no <code> post_title </code> in <code> WP_Query </code> 's parameter list . You need to use <code> name </code> , which accepts a slug not the actual post title. name (string) - use post slug. It looks like all you are doing is getting an ID. That is a very heavy query if that is all you need. You can alter th...
WP_Query returns more results than expected
wordpress
Im trying to output category with its post on a single page, but for some reason the post from all category are repeating in each category, what am i doing wrong here Here the code: <code> &lt;?php #Template Name: food get_header(); ?&gt; &lt;?php $taxonomy = 'category'; $param_type = 'category__in'; $term_args = array...
You are calling a weird parameter in line 24 which i dont understand... did you copy paste this function from elsewhere? anyhow... change line 24 from: <code> '$param_type' =&gt; array($term-&gt;term_id), </code> To this: <code> 'cat' =&gt; array($term-&gt;term_id), </code> Good luck and dont forget to read @toscho com...
Why is my category post repeating twice
wordpress
I'm trying to have alternating classes on the list created by wp_list_pages. Currently I have extended the Walker_page class updating the start_el function as follows: <code> class Sidebar_walker extends Walker_page { var $alternate = 'background_1'; function start_el( &amp;$output, $page, $depth, $args, $current_page ...
Consider this a complement to toscho's solution. I believe that ... <code> $this-&gt;alternate = ($this-&gt;alternate != 'background_1') ? 'background_1' : 'background_2'; $css_class[] = $this-&gt;alternate; </code> ... will do what you want. The difference is that toscho's solution, using the <code> static </code> key...
alternating classes on wp_list_pages
wordpress
I learned from stackexchange-url ("a previous question") that plugin updates are downloaded as a zip file, and WordPress overwrites every file in the plugin folder whether or not that file actually had a change from one version to the next. My question is, if the user has added extra files to the plugin folder (such as...
Yes, the entire old directory will be deleted. So store files in the upload directory and other data in the database to keep all changes. From class <code> Plugin_Upgrader </code> : <code> //Hooked to upgrade_clear_destination function delete_old_plugin($removed, $local_destination, $remote_destination, $plugin) { glob...
Do extra plugin files get deleted during an upgrade?
wordpress
What would be the correct way to assign a different name to each transient for each instance of a plugin used as a widget or shortcode?
Transients have practical limitation on key length (45 symbols or something like that), so using dynamic keys tends to come with risk of ending up with keys too long and having it break down. One of common practices is to form unique string (for example combination of plugin name and type of data being saved, etc) and ...
Transient unique names
wordpress
I am trying to create a child theme so theme updates are much easier. I want to remove the parent theme menus and add my own. I know I can modify the header.php file (where these menus exist) and edit the wp_nav_menus directly, but I'm trying to avoid using as many theme files as possible, so I'm trying to accomplish t...
You can filter <code> 'wp_nav_menu_args' </code> , set an invalid <code> theme_location </code> and the magic function <code> __return_false </code> as fallback: <code> add_filter( 'wp_nav_menu_args', 'override_parent_args' ); function override_parent_args( $args ) { if ( 'header-menu' === $args['theme_location'] ) { $...
Unregister Nav Menu with fallback?
wordpress
Scenario: there is a 'Recommended Books' section on the website which uses the 'book' custom post type and the 'author' custom taxonomy . I'm using Amazon Product Advertising API for retrieving book data and covers. When adding a new 'book' into WordPress, the user copies the book ID (ASIN) into the post edit field, an...
So, to answer my own question: I haven't found any solution inside <code> wp_insert_post_data </code> . I suspect that the problem is connected to the fact that when <code> wp_insert_post_data </code> is executed the post in question is not yet in the database. And albeit I didn't manage to find it in <code> taxonomy.p...
How can I add programmatically custom taxonomy terms to a custom type post when saving posts?
wordpress
EDIT: Adding more background info. I've coded a plugin that adds a meta box to the post page. When the post is published, the plugin will generate a random ID for the post, and insert the random ID and the post guid to a custom table in the database. After publishing, or upon editing, the plugin queries the custom tabl...
I've solved the problem myself though it is probably not be the right way to do it. Note that I've had to type "website-address" instead of the actual URL because system here won't let me use more than one URL in a post without more reputation. That makes it quite difficult to convey what's actually going on of course,...
$wpdb returns no results with SELECT query on custom post type, works on default post type
wordpress
I am using the german Wordpress 3.5.1–de_DE with Woocommerce 2.0.8 and the Woothemes Mystile Theme 1.2.8. I have a big picture for a product (Jellyfish.jpg) and want to use a specific area of that big picture as a thumbnail, because Wordpress/Woocommerce automatically chooses a not useful part of the image. So I used t...
You can fix this using the following code snippet from Brian Krogsard, that I modified. This code should preferably be placed into the functions.php file of your child theme. Instead of taking the original 150x150 thumb it now takes the correct, cropped 150x150 thumb. <code> /* This snippet removes the action that inse...
Woocommerce: Set thumbnail detail (clipping area)
wordpress
I'm attempting to style lists in the sidebar (you know, <code> &lt;ul&gt;&lt;li&gt; </code> ) and I'm curious how to also make widgets adopt this class. Each widget seems to have its own class assigned to it by WordPress' defaults - is there a way to override this?
As alluded to by @Michael in the comments, the CSS classes for widgets depend on the sidebar they're in more than the widget themselves. Those widget-specific CSS classes can be useful, but not when you're trying to style every widget. It sounds like you may be able to use a normal element selector that targets anythin...
Override WordPress Widget CSS Classes?
wordpress
A client gave a WP page to fix some problems. Specifically, there was a front end profile page that was not updating information as it was meant to. After I started testing, it all updates, but if you update your password it leaves you logged in. What I want to happen is to log the user out, send them to the login page...
in your script, after you update the data use wp_logout() and wp_redirect() or wp_safe_redirect() <code> wp_logout(); wp_redirect( home_url() ); exit; </code>
Redirect after password update
wordpress
I have two plugins in the dashboard, SEO Wordpress and Custom Content Type Manager , and for security reasons I want to hide these from dashboard. How to do that? I tried to hide the SEO Wordpress with this: <code> // Remove Admin Dashboard menus function wp_admin_dashboard_remove_menus() { global $menu; $restricted = ...
Wordpress SEO If you want to remove the admin menu: you can do that with: <code> function hide_wpseo() { remove_action('admin_menu', 'zeo_options_menu'); } add_action( 'init', 'hide_wpseo'); </code> where it will be removed for all users. WordPress SEO by Yoast To hide the admin menu: and the admin menu bar: one can us...
Hide widgets/plugins from dashboard
wordpress
I've this function, which I'm pretty sure a lot of you already know: <code> function catch_that_image() { global $post, $posts; $first_img = ''; ob_start(); ob_end_clean(); $output = preg_match_all('/&lt;img.+src=['"]([^'"]+)['"].*&gt;/i', $post-&gt;post_content, $matches); $first_img = $matches[1][0]; return $first_im...
When the first image is a Wordpress image attachment. in 3.6, there is an easier way. <code> function get_first_image_medium_size_url($post_id) { if(!$images = get_attached_images($post_id)) return false; $first_image = current($images); if(!$src = wp_get_attachment_image_src($first_image-&gt;ID,'medium')) return false...
Use 'medium' size with catch_that_image() function
wordpress
As the title says. Would be grateful for your help. Thank you.
Try to do all theme modifications in functions.php whenever possible. It keeps the theme files clean and uncluttered. Here's an example using the <code> pre_get_posts </code> action : <code> function order_category_archives( $query ) { if ( is_category() &amp;&amp; $query-&gt;is_main_query() ){ // is_category() can spe...
How to modify category.php to list posts alphabetically?
wordpress
I was wondering, is it possible to set default text to appear inside "text" part of the wysiwyg located on Create post page? So every time you click add new post that text would be there waiting for you?
There is a filter named <code> default_content </code> . It does exactly what the name says. :) Example: <code> add_filter( 'default_content', 't5_preset_editor_content', 10, 2 ); /** * Fills the default content for post type 'post' if it is not empty. * * @param string $content * @param object $post * @return string *...
Set default text for the editor in new posts
wordpress
By default in woocommerce when a user wants to add a review of a product, they click 'add a review' and this opens up a pop-up lightbox. I want to disable this part and just display the review form. Anybody has any ideas?
Here's a hack you can use. Update: As Andrew Bartel mentioned below. It's best to copy the template files into your theme so that they override the default woo commerce template files. In your woocommerce plugin folder, look for a file called product-reviews.php <code> woocommerce/templates/single-product-reviews.php <...
How to disable lightbox popup for "add a review" only?
wordpress
I have tried many things to solve this problem. So I have a plugin which displays projects assigned to users in a widget. It displays projects as posts. The problem is that it only displays <code> 5 </code> projects on the page. I am sending a code which display posts: <code> $projects = get_posts(array('post_type' =&g...
The WordPress function <code> get_posts() </code> supports: <code> 'posts_per_page' =&gt; 10, 'numberposts' =&gt; 10, </code> so you should use: <code> $projects = get_posts(array('post_type' =&gt; 'projects', 'numberposts' =&gt; 10)); </code> instead of <code> $projects = get_posts(array('post_type' =&gt; 'projects', ...
Number of displayed posts
wordpress
I redesigned an old (static) website to WordPress CMS. Now that site is WordPress based with 'blog' as a page displaying all posts. On previous (static) version, they already had a separate WP blog inside /blog directory. I imported all old blog posts to our new WP setup but problem is with images. On old blog, images ...
This is not answering the exact question you posed, but as as far as I am concerned, your current attempt is the wrong approach to solve the problem of wrong image paths after moving anyway. Rather than what you are attempting to do, either replace the image paths in the database, or redirect those. While replacing/upd...
WordPress .htaccess to consider blog as directory
wordpress
I have a costume search in a site i am making. When a user search a certain term, i want to display category list with a count of how many posts are found with in that category. I thought of a way but i have problems doing it. in search.php in the loop in <code> have_posts() </code> , i will add a line that check each ...
This is what i did: I run another query without pagination like this: <code> $newQuaryVars = '&amp;posts_per_page=99999999999999&amp;post_type=post'; $posts = query_posts($query_string .$newQuaryVars); $categoriesList = array(); $categoriesAmounts = array(); </code> Then in the <code> while have posts </code> i did the...
Trying to find a way to query post like normal search would do. within search.php page
wordpress
I need to check each page to see if it has a default template or another template assigned. If it's default, I want to do X if it's not, then I will do Y. Problem I found is that the query is not showing that particular field. I wanted to find <code> [meta_key] =&gt; '_wp_page_template', [meta_value] =&gt; 'default' </...
When you are in your <code> while </code> loop, the parent query is already finished. So fetch the post meta value with <code> get_post_meta() </code> : <code> $template = get_post_meta( get_the_ID(), '_wp_page_template', TRUE ); </code>
get meta value from page query
wordpress
It's a sad day in the world when I Google something and it returns nothing. I am trying to use the default datepicker (or ANY datepicker at this point) and am unable to because of my lack of knowledge with Wordpress/PHP. In my plugin, I am attempting to register jquery and the ui and apparently am breaking other parts ...
Given that all of the libraries you need for the datepicker are bundled with WordPress and are registered with all of the appropriate dependencies, all you really need to do is: <code> function enqueue_my_scripts_wpse_97533() { wp_enqueue_script('jquery-ui-datepicker'); } add_action('wp_enqueue_scripts','enqueue_my_scr...
How Do I Use jQuery UI In My Plugin
wordpress
I have chosen to display a login form in the first page of my wordpress website. If the user logs in successfully, he gets redirected to a specific webpage. If he enters a wrong password, he gets redirected to the login page again. The problem happens when someone does not enter username and password: he gets redirecte...
Check for an empty user login in the <code> $_REQUEST </code> array: <code> if ( empty( $_REQUEST['user_login'] ) // &amp;&amp; or || empty( $_REQUEST['user_pass'] ) return $redirect_to_whereever_you_want; </code> But this filter is to late. It is called after the user is logged in. You have to use the <code> 'wp_authe...
Redirect after empty login username and password
wordpress
I know many people asked for this question but I didn't find a proper way to do it. How to add a simple meta_query (product_cat) before the execution of the shop page's query. Maybe by using a filter ? Regards, Adrien
The shop page is actually an archive page for posts of type 'product'. Its template is in woocommerce/archive-product.php. You need to use the pre_get_posts action to preprocess the query before the loop, conditional_tags to recognize that you are in the product archive page, and a taxonomy query to filter the product ...
Display products from specific category in shop page
wordpress
FINAL UPDATE: Updated code from @birgire solved my issue. If you are facing a similar issue, please read the accepted answer. ORIGINAL QUESTION IN DETAIL: Currently under the appearance menu in admin, there is a link called 'editor', which when clicked leads to editable main-stylesheet, my effort is to put a link to a ...
You can check out stackexchange-url ("this") excellent answer by @Eugene Manuilov. In your case the relevant admin page action is: <code> load-appearance_page_customstyle </code> and the url to the custom stylesheet you want to edit: <code> get_admin_url().'theme-editor.php?file=custom-stylesheet.css&amp;theme='. get_s...
place a direct link to custom-stylesheet, under appearance menu in wp-admin
wordpress
I'm using xdebug and webgrind to profile my WordPress installation because it's a bit slow. As there are some 20 plugins activated, I figured xdebug will be able to find the bottleneck. However, to my surprise, it appears that localizing routines are taking the majority part of the execution time. And yes I'm using a l...
For each translation file, WordPress has to unpack it, then each entry will be converted into an <code> Translation_Entry </code> object. The short string "caller_get_posts" is deprecated. Use "ignore_sticky_posts" instead. will need three times more memory when it is translated: <code> '"caller_get_posts" is deprecate...
Localized WordPress is much slower?
wordpress
So, after poking around in the code it looks like the filter <code> image_make_intermediate_size </code> is not called by the various <code> WP_Customize_Control() </code> classes at either <code> WP_Customize_Image_Control() </code> or it's parent <code> WP_Customize_Upload_Control() </code> . I'm looking to auto-gene...
If someone has a better solution, I'm open to it, however, what I came up with seems to work fine. Basically the following code is just waiting for the image to finish uploading and then hooking into the <code> add_attachment </code> action. Once the first is added, we hook in and then generate the new images via the p...
Responsive Images - Generating multiple images from Theme Customizer control upload?
wordpress
Well as you can see here im doing a load by category in every tab i have and show a total posts of 10 by each tab i want to setup once the 10 posts are done. i want to add a load more button to the bottom of the 10 posts i have done that but the viewer has to see the rest of the posts else where for a specific category...
You will need to load the next 10 posts with an AJAX request and keep the current offset stored in the DOM. Attach an ID to the <code> &lt;span&gt; </code> element which is your button, in my example I have used <code> #load_posts </code> . Then using jQuery, you can easily setup the click event for the button to fire ...
load more posts by category
wordpress
What I am trying to accomplish is to update a taxonomy term name using its slug rather than the $term_id Wordpress does this by: <code> &lt;?php wp_update_term( $term_id, $taxonomy, $args ) ?&gt; </code> Is it possible to do this via the slug instead? <code> &lt;?php wp_update_term( get_term_by( 'slug', $value, $taxono...
As you hinted in your question, you could use <code> get_term_by() </code> to return an object or array containing the term's id, then use it to update that term. Something like this should work: <code> $your_term = get_term_by( 'slug', 'your_slug', 'your_taxonomy' ); if ( false !== $your_term ) { wp_update_term( $your...
Changing taxonomy term by slug (wp_update_term)
wordpress
How can i use more than 20 sidebars in wordpress. I'm working on a big information portal, and I need big amaunt of sidebars (about 40, I guess). So I have 20 sidebars now and when I add one more it overrides one of the previous entered. I searched the web about similar problems, but I found nothing ... Can somebody he...
Just tried it on a test install with twenty-something sidebars, all works fine. Note that <code> id </code> parameter should be unique between all of them. <code> name </code> doesn't have to be, but it's nice to keep it unique as well so as to avoid confusion in the admin UI. <code> register_sidebar( array( 'name' =&g...
How to increase maximum number of sidebars support?
wordpress
I have been trying to size my screenshot.png for my theme to 300x255 without losing aspect ratio. I have been doing this by getting my browser window width on my laptop to a size that is proportional to 300x255 so that I will get a screenshot without distortion but has not worked. Moreover, I am working with a fixed wi...
I got around this problem by doing the following steps. Find out screensize we will call this <code> &lt;screenwidth&gt; </code> and <code> &lt;screenheight&gt; </code> for now. I made my browser fullscreen. I used Chrome for this as the header bar disappeared and I got the full screen height for my screenshot. This is...
Sizing screenshot.png without losing aspect ratio
wordpress
My question is related to stackexchange-url ("this one"). I would like my post permalinks to be prefixed by <code> /blog/ </code> , but I don't want this prefix to be applied to my custom post type portfolio . In other words, I expect post links to use <code> /blog/ </code> and portfolio links to use <code> /portfolio/...
The parameter you are using is wrong. There is no <code> set_front </code> parameter when you register a Custom Post Type . The appropriate parameter is <code> with_front </code> . 'with_front' => bool Should the permastruct be prepended with the front base. (example: if your permalink structure is /blog/, then your li...
"set_front" => false on custom post type breaks wp_list_categories links
wordpress
The navigation menu of my site is generated via <code> wp_nav_menu( array( 'theme_location' =&gt; 'primary') ); </code> Some menu entries are category pages (say <code> /category/news/ </code> ). This page contains links to the next level, single post posts (say <code> /news/123/ </code> ). I noticed that the menu is o...
You can target the <code> .current-menu-parent </code> class in your CSS to keep the category highlighted when viewing single posts.
Keeping 'current-menu-item' highlight of navigation menu?
wordpress
i know this might sound a bit weird, but what I'm trying to do is rather simple in mind but may be technically difficult. I'm running small contests on my wordpress site where I ask users to leave a comment. I'm selecting a comment after a certain period of time and this is the winner. What I'd like to do now, is mark ...
Assuming you'd like the facility to update this data from the quickedit box whilst viewing the list of comments, you'll need a series of actions and filters. I've tried to make appropriate comments in the necessary places for you, though bear in mind i threw this all together for you with a small amount of testing(it d...
Adding another state (spam, reject, approve) to wordpress comments?
wordpress
I've been building a theme completely from scratch and after a straightforward process up to this point, I've reached the comments.php file. Again, nothing too out of the ordinary, until this: $callback (string) (optional) The name of a custom function to use to open and display each comment. Using this will make your ...
If you prefer simple template files, you can do that with custom comment callbacks too. Call <code> wp_list_comments() </code> with a custom callback handler: <code> wp_list_comments( array( 'callback' =&gt; 'custom_comment_callback', 'style' =&gt; 'ol' ) ); </code> Now make that callback function very simple: <code> f...
Why is styling comments so complex?
wordpress
I don't believe there's a <code> is_new_year() </code> function in WordPress, as an alternative for <code> is_new_day() </code> . I'm trying to display the year only once for each set of posts, what would be the best way to do this? Should I just check the date manually with PHP in the loop or are there any better ways...
You could create a helper function that returns a year number only once per year: <code> function get_unique_year( $post_id = 0 ) { static $last = 0; $post_id || $post_id = get_the_ID(); $year = get_the_time( 'Y', $post_id ); if ( $year === $last ) return; $last = $year; return $last; } </code> Then fetch your posts an...
"is_new_day()" alternative for years?
wordpress
I am using the following custom walker to hide the Login and Register pages from my navmenu created with wp_get_nav_menu_items..... <code> function wpse31748_exclude_menu_items( $items, $menu, $args ) { // Iterate over the items to search and destroy if ( is_user_logged_in() ) { $registerpage = get_page_by_title( 'Regi...
You can try the <code> !is_admin() </code> so your code would be: <code> function wpse31748_exclude_menu_items( $items, $menu, $args ) { // Iterate over the items to search and destroy if ( !is_admin() &amp;&amp; is_user_logged_in() ) { $registerpage = get_page_by_title( 'Register' ); $loginpage = get_page_by_title( 'L...
Limit Custom Crawler to front end only
wordpress
I'm tryin to use this accordion script in my WP: http://www.armagost.com/zaccordion/ Problem is that on a standalone html/php file it works well but once pasted in my header.php file there's no way to make it work. I tried also including it with <code> &lt;?php require_once("example.php") ?&gt; </code> but no success. ...
You seem to still be having issues, what i'd do to avoid having all that code clutter the header is setup a bunch of enqueues, but handle the html5 js inside the print scripts action along with the appropriate conditional comments(there's no proper way to do this with the enqueue system). First the HTML5 js, outright j...
jQuery accordion plugin won't work once used in WP
wordpress
Recently i have updated my wp site to the latest version and since then post editor not working, What i have tried: Disabled all plugins. Installed "Use Google Libraries". Disable all plugins except "Use Google Libraries". Re-install WordPress from the update panel. Followed some solutions on WordPress support: Adding ...
Well this is embarrassing. I found the culprit, it was one of my theme :( Enabling Twenty Twelve solves the visual editor issue. Sorry guyz and thanks for the support.
Post Editor not working on WordPress 3.5.1
wordpress
Made template but how to make date to show only in posts not anywhere else? <code> &lt;div class="date"&gt;&lt;strong&gt;&lt;?php the_date(); ?&gt;&lt;/strong&gt;&lt;/div&gt; </code> This makes date to show in Home, Pages but i need only for posts. Something like if is post then the_date(); ?
There are two options: Create a separate <code> single.php </code> for posts and show the date there only. Use a condition: <code> if ( is_single() ) { ?&gt;&lt;div class="date"&gt;&lt;strong&gt;&lt;?php the_date(); ?&gt;&lt;/strong&gt;&lt;/div&gt;&lt;?php } </code>
How to make only posts show date
wordpress
I made it possible to use post-new.php?post_cat=catslug in the wordpress admin for creating a new post with a pre-filled category by using the answer here: stackexchange-url ("How to add category to: &#39;wp-admin/post-new.php&#39;?") Now I want to create multiple menu items with this format under the "Posts" -> "Add n...
To see the the current array keys try this: <code> add_action( 'admin_menu' , 'admin_menu_new_items', 1 ); function admin_menu_new_items() { global $submenu; wp_die( '&lt;pre&gt;' . var_export( $submenu['edit.php'], true ) . '&lt;/pre&gt;' ); } </code> I get this: <code> array ( 5 =&gt; array ( 0 =&gt; 'All Posts', 1 =...
Add post-new.php?post_cat=catslug to admin menu
wordpress
Made own template from scratch and tutorials. This is showing description of post/page Title and in home its showing website name. <code> &lt;h3&gt;&lt;?php is_home() ? bloginfo('description') : wp_title(''); ?&gt;&lt;/h3&gt; </code> I wanted to change that if home page then that it writes News and if page then its nam...
Put this in your <code> functions.php </code> : <code> function my_title() { if (is_home()) echo 'News'; else { global $post; if ($post-&gt;post_parent) echo get_post($post-&gt;post_parent)-&gt;post_title; else echo $post-&gt;post_title; } } // function my_title </code> and then use <code> &lt;?php my_title(); ?&gt; </...
How to make title for home to be News, but if page has parent then its name else just post/page name
wordpress
I have a function for displaying the title of the top-level page of the current sub-level page. It's working quite well, but I can't figure out how to also link to the same top level page that is displayed. <code> function my_page_ancestor() { global $post; if( !is_front_page() ) { $parents = get_post_ancestors( $post ...
You may want to try get_permalink() ie: <code> get_permalink( end($parents) ) </code> . :-)
Getting the top level permalink using get_post_ancestors()
wordpress
When a user updates a plugin from the WordPress admin panel, does every plugin file get overwritten, or just the ones that have changed from the previous version? For example, let's say that a plugin has 3 files: a.php, b.php, and c.php Version 2.0 has changes to a.php and b.php; c.php was unchanged. However, the user ...
When you update a plugin you just get a new Zip-file containing the whole plugin. You don't get the information which files in that archive changed. That's the reason why all files are overwritten.
Which files get updated in a plugin update?
wordpress
I have 4 footer widgets in the theme I'm working on. It works great. The only thing that I can't get to work is the responsiveness of the widgets. The 4 footer widgets keep on showing up next to each other on smaller screens, and I need them to be on top of each other for smaller screens. Can any one help me around thi...
Set the width of the div to 100% and remove the float for the media query used for smaller screens like this: <code> @media screen and (max-with 600px){ .widget-area{ float: none; width: 100%; } } </code> And for the desktop view: <code> @media screen and (min-with 600px){ .widget-area{ float: left; width: 25%; } } </c...
Making footer widgets responsive
wordpress
I'm developing a Custom Post Type plugin, which works fine in dev. Now that I've moved it to production, I'm getting a 404 when I try to display the template for the CPT. So, two questions: 1- Is there some mechanism to determine the path WP took to get through the hierarchy? 2- Why wouldn't it just give me the single ...
Always flush the rewrite rules when you register a new public post type or taxonomy. Otherwise the internal rewrite rules will not take that into account when an URL is mapped to a query. You can automate that process by hooking into <code> registered_post_type </code> and <code> registered_taxonomy </code> . Below is ...
CPT Template Not Showing - Getting 404
wordpress
I'm thinking about hosting a WordPress website with agressive caching/optimization strategies (like varnish, microcache, ngx_pagespeed, etc). But I still want Jetpack stats to work alright. What should I pay attention to? How does jetpack-stats count visits? tracking images? AJAX calls? internal WP hooks? Depending on ...
Let me quote what's mentioned in the official FAQ of WordPress.com Stats plugin (JetPack statistics module uses this plugin as the base)... The plugin collects stats via a javascript call, so as long as the JS call is on the page stats will be collected just fine, whether the page is cached or not. In short, you don't ...
Jetpack stats and caching strategy
wordpress
Background I have a registration form that validates with AJAX using jQuery Validation Engine . The form was created using Theme My Login and contains reCaptcha which I implemented using WP-reCAPTCHA . Just like the rest of the fields, I needed to validate reCaptcha using AJAX as well, that is, without refreshing the w...
Just found out that reCaptcha actually rejects CAPTCHAs which are submitted to their server more than once . Since I was using the WP-reCAPTCHA plugin , the plugin resubmitted the CAPTCHA after my AJAX submission. So I just commented out a line from the plugin that does the submission, which is in file <code> recaptcha...
Ajax Validation for reCaptcha
wordpress
I am relatively new to jQuery and AJAX in particular. I have a small issue with the return value always being 0, though I think this is actually the success message and it's not returning anything. I have scoured the Google-verse and I have the die() function on the PHP callback and I believe the add_actions are correc...
So I worked it out. It was not the jQuery as such though I have improved that, it was the placement of the call back function. I moved it over to the main plugin file and it worked.
Admin Ajax is returning 0
wordpress
I was given a task to move the content and certain familiar navigation elements from an old WP-based website to the new one, based on the latest version of WP. The blog page of the old site has the number links to the old posts near the bottom of the page: How can I create the same links in TwentyTwelve category page? ...
First, that old site is not any version of WordPress. Second, don't hack TwentyTwelve, make a child theme . if you hack it, your changes will be lost when the theme is updated. Third, the easiest way to achieve pagination like that would be WP-PageNavi .
Display category page number links for older posts
wordpress
I want to create features list in wordpress post. I know how to do in CSS but I was wondering if it can be done by using a short code or a plugin?. Like <code> [features_list] Item 1 Item 2 [/features_list] </code> Example:
Convert the items in the shortcode into an array, and return a list: <code> add_shortcode( 'features_list', 'shortcode_features_list' ); function shortcode_features_list( $atts = array(), $content = '' ) { $content = trim( $content ); if ( '' === $content ) return; $items = explode( "\n", $content ); $items = array_map...
Creating Features List in Wordpress Post
wordpress
I'm using the Query Multiple Taxonomies plugin to get a page of search results (all of which are a custom post type - car). If any search terms are added, so the url looks like this: <code> http://mysite.com/car/?makemodel=ford&amp;body=&amp;gearbox=&amp;fuel=&amp;minprice=&amp;maxprice= </code> then the archive.php te...
You could filter <code> template_include </code> : <code> add_filter( 'template_include', 'wpse_97347_force_archive' ); function wpse_97347_force_archive( $template ) { if ( isset ( $_GET['makemodel'] ) &amp;&amp; empty ( $_GET['makemodel'] ) ) return get_archive_template(); return $template; } </code> Not tested.
Query with no terms uses index.php template instead of archive.php
wordpress
I want to make changes to code of the Recent Posts widget – could anyone please tell me where that code is located? Thank you in advance!
The default Recent Posts Widget code is in <code> includes/default-widgets.php </code> but you should not be hacking Core code. Copy that function to your theme's <code> functions.php </code> , rename it, and create your own customized widget.
Code for Recent Posts Widget
wordpress
I want to know, what script drives the "screen options" animation toggle in WordPress. I'm referring to the options menu that slides out when the admin clicks the "Screen Options" link near the upper right corner of the window in the Post, or Page, or Categories, etc. – and slides back in when the same link is clicked ...
This is in <code> wp-admin/js/common.js </code> or <code> wp-admin/js/common.min.js </code> : <code> // Scroll into view when focused $('#contextual-help-link, #show-settings-link').on( 'focus.scroll-into-view', function(e){ if ( e.target.scrollIntoView ) e.target.scrollIntoView(false); }); </code> Found with a search ...
Screen Options JavaScript Code
wordpress
My theme's <code> functions.php </code> hooks into <code> wp_enqueue_scripts </code> to register a couple of stylesheets that are used by various site pages. Here's a simplified version of my configuration: <code> add_action("wp_enqueue_scripts", function() { // This stylesheet is used on *every* page wp_register_style...
Check the current template in your callback. This is a post meta field named <code> _wp_page_template </code> . <code> add_action("wp_enqueue_scripts", function() { // This stylesheet is used on *every* page wp_register_style("sitewide", get_template_directory_uri() . "/assets/sitewide.css"); wp_enqueue_style("sitewide...
How can I let templates choose which stylesheets are enqueued?
wordpress
I would like to have a form with checkboxes. Each checkbox would be a term of my taxonomy "cities". The idea is that if a user select any of the checkboxes, it should show all posts that are NOT in marked terms. If I had this code: <code> $args['tax_query'] = array( array( 'taxonomy' =&gt; 'cities', 'terms' =&gt; array...
You can run a query with a <code> tax_query </code> parameter which excludes certain taxonomy terms. See stackexchange-url ("this answer"). As for where to run the query, you can either have a form that submits to the page it's on (you'll need to locate an appropriate template file being called for that page or create ...
How to display posts via custom taxonomy terms using checkboxes?
wordpress
I want to modify the date display of the post entries from current format: April 26, 2013 to this: 04/26/2013 Where in the code can I make this change? Thank you in advance!
<code> the_time( 'm/d/Y' ); </code> or <code> the_date( 'm/d/Y' ); </code> Note, <code> the_date() </code> will not print the same value twice. If a second post would get the same output you get nothing. If your theme doesn’t set a fixed value, like Twenty Twelve … <code> get_the_date() </code> … then the format is tak...
Display post date as 04/26/2013
wordpress
I have a static front page that checks if the user is logged in, and if he/she is a number of x posts from a specific category is displayed. For that I was using this code: <code> query_posts('cat=2&amp;showposts=5'.'&amp;orderby=date&amp;order=desc'); while (have_posts()) : the_post(); the_content(); endwhile; </code>...
Without seeing the broken code it is hard to say, but your filter should look something like this: <code> function pregp_wpse_97354($qry) { if (is_front_page() &amp;&amp; is_main_query() &amp;&amp; is_user_logged_in()) { $qry-&gt;set('cat',2); $qry-&gt;set('posts_per_page',5); $qry-&gt;set('orderby','date'); $qry-&gt;s...
Replace query_posts with pre_get_posts
wordpress
In apply_filters() <code> apply_filters( $tag, $value, $var ... ); </code> I'm having trouble wrapping my head around the <code> $value </code> and <code> $var </code> . I read the codex and it sounds like the <code> $value </code> can be modified, <code> $var </code> not, but I haven't found any examples of this in th...
Try to see the function with better names: <code> apply_filters( $filter_name, // used for add_filter( $filter_name, 'callback' ); $value_to_change, // the only variable whose value you can change $context_1, // context $context_2 // more context ); </code> So when that function is called as: <code> // wp-login.php lin...
Trouble understanding apply_filters()
wordpress
I have create a user role using Advance Access Manager wordpress plugin having role to see, add and remove users name as site_admin. When user login with his Id he is able to see the adminstrator and edit his profile. I remove that thing by using this code. stackexchange-url ("Remove Ability for Other Users to View Adm...
I think something like this should work just fine: <code> function my_views_users($args) { $hidden_role = 'administrator'; // it will hide filter with role 'administrator' - you can change it to some other role $users_counts = count_users(); $total_users = $users_counts['total_users'] - $users_counts['avail_roles'][$hi...
Remove Adminstrator Hyperlink from a user having role to add and see users
wordpress
Hi I'm using the smarty templating engine in wordpress to generate HTML like the one below: <code> &lt;li&gt; &lt;div class="checkbox_container" data-asin="B0009Y7APU"&gt;&lt;input type="checkbox" class="ecom_compare_products" data-asin="B0009Y7APU" value="B0009Y7APU"/&gt; &lt;/div&gt; &lt;div class="small_img_containe...
Found the answer. I hope this would be useful to others that might have this problem in the future. All you have to do is remove the <code> content_save_pre </code> filter and <code> content_filtered_save_pre </code> this will remove all Kses input form content filters. <code> //temporarily disable remove_filter('conte...
Wordpress removing data attributes for scheduled post
wordpress
I would like to be able to use the jQuery Fancybox's Ajax feature to request datas from the front-end. Here is a part of the code i'm using on the plugin part : <code> wp_localize_script( 'wpPluginjs', 'ajax_vars', array( 'url' =&gt; admin_url( 'admin-ajax.php' ), 'nonce' =&gt; wp_create_nonce( 'ajax-nonce' ) ) ); </co...
<code> &amp;nonce </code> should be <code> ?nonce </code> . The <code> ? </code> begins a query string, the <code> &amp; </code> separates arguments within a query string.
Ajax requests from front-end with jQuery Fancybox
wordpress
I'm working on an advanced search (which uses custom sql queries), and the query string is formed using variables. For example, if the person checks some options, only those conditions get added to the WHERE clause. I can't use <code> $wpdb-&gt;prepare </code> , since I want to be able to add variables to my query stri...
I can't use $wpdb-> prepare, since I want to be able to add variables to my query string that look something like: <code> $var = "AND pm.meta_value = '%$_POST['val']%'"; </code> To get a literal <code> % </code> to pass through <code> $wpdb-&gt;prepare </code> just double it. You don't need to be avoiding <code> $wpdb-...
How to properly sanitize strings without $wpdb-> prepare?
wordpress
I'm new to WordPress and trying out woocommerce, but I've ran into a small problem. Here is my site . The products pages are no childs of the Shop page, so whenever I click on a product, the active underline under Shop disappears. Does anyone know how to change this? Im using the Mystile theme.
You don't need to force the permalink structure to do this. These effects are usually handled by adding some class (with a specific style) to the item you want to highlight, in this case the <code> &lt;li&gt; </code> containing the link to the shop. In your site, the Shop menu entry (when in the Shop page) is: <code> &...
Woocommerce - Making product pages child of shop
wordpress
I want to display a unique message on the post (single.php) page outside the loop on author box. I want the message to be different depending on the author's capabilities. So for instance, if the author can <code> manage_options </code> then echo <code> this is admin </code> , else if the author can <code> edit_others_...
Use <code> global $authordata </code> : Testing for roles: <code> global $authordata; if ( in_array( 'administrator', $authordata-&gt;roles ) ) { echo 'Hello Admin!'; } elseif ( in_array( 'editor', $authordata-&gt;roles ) ) { // echo something else } </code> Or testing for capabilities: <code> if ( ! empty ( $authordat...
Display message depending on capability outside loop
wordpress
No, I've never made a plugin. But I would like to, or find someone who can work with me on it. What I'm hoping to accomplish is setup presets on site creation. I need my multisite to do this: When creating a site, require information from the user creating it that is not normally requested. Upon obtaining this informat...
To create a basic plugin, add a directory in <code> wp-content/plugin </code> , then put a php file in it with the required header , and that's it. Now, here is how to use the action : <code> add_action( 'wpmu_new_blog', 'user16975_customize_blog', 10, 6); function user16975_customize_blog($blog_id, $user_id, $domain, ...
Customize multisite site creation with user data
wordpress