question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
So, in my shortish WordPress development career, I've gotten in the habit of creating a "page" for the content in a footer, and adding different fields with the wpalchemy class. Everything with this approach seems to work fine, except for the fact that users can go to mysite.com/footer and see something I do not want t...
I don't think there's anything fundamentally wrong with your approach, I see it pretty often. You could hook <code> parse_request </code> and 301 redirect any requests to footer to the front page. I wonder though how visitors would end up there in the first place, as long as you exclude it from the sitemap and don't li...
Putting footer content in a "page" - Doing it wrong?
wordpress
I am currently developing a social-network sort of site using Wordpress + Buddypress and the client has asked that profile pages not be publicly visible for the time being. Basically the client is okay with logged in users viewing their own profiles, but if they try viewing a profile page of another user it should redi...
I solved this issue myself, it was quite easy and I'm surprised nobody else supplied an answer. Having said that, the solution is to add a few lines of code that check what the author ID is of the profile you're viewing and compare it to the ID of the currently logged in user. This code goes at the top of members/singl...
How To Only Allow Users To View Their Own Buddypress Profiles?
wordpress
Hi my wordpress admin is acting really slow, is there some diagnostic plugin I can use (like Debug queries on the front end) to see which plugin is slowing down the dashboard?
First i recommend you to use Chrome Ctrl+Shift+j -> Timeline, click record button and refresh admin page and in that timeline you will see what caused the longest load. if HTML then php/sql part is slow, but maybe some javascript causes slow load. Second - one by one disable plugins and test loading time.
WordPress Admin very slow
wordpress
I'm building a post grid on my front page and I'd like to show one random post per CPT. At the moment, CPT are queried out in a query array: <code> &lt;?php $c = 1; //init counter $bpr = 3; //boxes per row $wp_query = new WP_Query(array('showposts' =&gt; 9, 'orderby'=&gt; 'rand', 'post_type' =&gt; array('productions', ...
This method might work for you. You will have to grab more posts than you need but it is better than doing 9 queries. <code> $args = array( 'post_type' =&gt; array( 'type1', 'type2', 'type3', 'etc...' ), 'posts_per_page' =&gt; -1 ); $myquery = new WP_Query( $args ); $type1 = 0; $type2 = 0; $type3 = 0; $count = 0; while...
One random post from multiple custom post types
wordpress
I am making a Wordpress theme and want to change the default image html. For example if you upload an image using Wordpress uploader it generates the following html for your images <code> &lt;a href="image_url_goes_here"&gt; &lt;img class="aligncenter size-full wp-image-100" src="your_src"/&gt; &lt;/a&gt; </code> I wan...
This will do: <code> &lt;?php /* * This filter only works with images, for all kind of media check: media_send_to_editor * The priority is set to 20 and it takes 8 arguments */ add_filter('image_send_to_editor', 'wpse_53577_img_wrapper', 20, 8); // We are only working with the $html argument, but you can play with all ...
Change Default Image HTML
wordpress
stackexchange-url ("This code works") for me if I go to upload a file and choose the Gallery or Media Library tabs then it correctly hides elements on the page. If I go to the From Computer or From URL tabs, nothing is hidden! If I take out the if statement then it works. I can't see why it shouldn't be working on thes...
Version 1 Deals with filtering based on Post ID *From Computer* tab we need to retrieve the <code> $attachment_parent_id </code> : <code> add_filter('attachment_fields_to_edit', 'wpse_53600_remove_media_upload_fields', 10000, 2); function wpse_53600_remove_media_upload_fields( $form_fields, $post ) { $our_page_id = 4; ...
Remove fields on media uploader for custom page type - not working for "From Computer" or "From Url" tabs?
wordpress
LATEST UPDATE (June 13th 2012) I can't figure out what's wrong with my codes. When I want to share one of my blog posts and use either the Facebook share button or copy the link of the blog post directly into Facebook all that pops up is the URL itself, not the meta info such as description or featured image! I filled ...
I'd guess this has something to do with your caching layer. The Facebook linter says it's getting a 206 response to the example link you posted. A 206 means the response contained only partial content, and is often the result of a caching mechanism. It also has some pretty strict validation rules, and your response hea...
W3 Cache plugin and Facebook sharing
wordpress
I don't know a lot of Wordpress yet, and I'm just wondering: Before installation you have to fill in the correct data in <code> wp-config-sample.php </code> but this also includes the database password. Isn't that dangerous? I mean, can some one explain how this is protected from just reading the file and thus getting ...
The "Hardening WordPress" page of the Codex contains a section on "Securing wp-config.php". It includes changing the permissions to 440 or 400. You can also move the wp-config file one directory up from the root if your server configuration allows for that. Of course there is some danger to having a file with the passw...
Password in wp-config. Dangerous?
wordpress
Hoping for some feedback on the topic of optimizing and staying on top of performance as a WordPress database grows... to paint a picture.... let's say you have a WordPress / Buddypress MU site that begins at around 150kb (vanilla install)... over time users add blogs, forums, posts, and comments and the database grows...
Your specific questions: 1) There is no strict limit to the "number of entries" a DB may contain before performance is affected. Performance depends just as much on your hardware and configuration as it does on the size and structure of the DB. 2) If you're worried about the scalability of your DB layer, you can run it...
What's a good strategy for planning WordPress DB growth?
wordpress
I'd like to customize the HTML output of the comment form. I've been reading I've been reading how to alter some variables of the comment_form() . The previous link provides a rather good guide to play with that function. But I'm still unable to change the HTML output of the form. And I would like to wrap some fields i...
Upon request, a bit more of inormation :) The default html output of comment_form() is: <code> &lt;p class="comment-form-author"&gt;&lt;label for="author"&gt;Name&lt;/label&gt; &lt;span class="required"&gt;*&lt;/span&gt;&lt;input id="author" name="author" type="text" value="" size="30" aria-required='true' /&gt;&lt;/p&...
Change the HTML output of comments
wordpress
i have setuped showing rss from my network site using fetch_feed(); <code> include_once(ABSPATH . WPINC . '/feed.php'); $rss = fetch_feed('rss link here'); $maxitems = $rss-&gt;get_item_quantity(5); $rss_items = $rss-&gt;get_items(0, $maxitems); THen i can use foreach to get these $item-&gt;get_description(); $item-&gt...
According to the Codex, fetch_feed() uses the SimplePie engine for parsing RSS. So, if <code> $item-&gt;get_title(); </code> is working, then you should be able to do: <code> $item-&gt;get_thumbnail(); </code> as per the SimplePie documentation , as long as there are any thumbnails already on the feed. UPDATE: Before r...
Getting Thumbnail in fetch_feed from custom field
wordpress
I have downloaded my site to a production environment. I have set up both the live site and the production site to use the same DB. When i login to the admin panel i get redirected to the live site. I know that wordpress stores URLs in the DB so i want to modify (hard code) my production site not to redirect anywhere. ...
I think getting the site to redirect to the proper location on login would only be the beginning of your issues with this setup. What would happen when you want to use any WordPress function to retrieve the site url? You would possibly have to re-write those functions as well, so that they return the production url ins...
Wordpress redirect on login
wordpress
I want to modify TinyMCE in WordPress so that it inserts media (image etc.) always at the beginning of post contents. For this I need to change the cursor position to the beginning, insert media and possibly restore old cursor position. I am not sure how to achieve it. Please advise.
I found this which helped me moving caret to start of post before inserting media. My modified code is: <code> var root = ed.dom.getRoot(); var node = root.childNodes[0]; if (tinymce.isGecko) { node = node.childNodes[0]; } ed.selection.select(node); ed.selection.collapse(true); // The following is required to work in I...
TinyMCE - Insert media at the beginning of post
wordpress
How can I create a moving skideshow similar to the one on this site ? Is there a plugin doing this already? I have searching using the "moving slideshow" keywords. Any tips? Many thanks.
It really depends what you want? If you need it to be controlled from the WordPress CP then you may have to write your own or try reading through the descriptions on these plugins listed here. - http://wordpress.org/extend/plugins/search.php?q=slider If you dont need so much control you can look into jQuery Slider plug...
Wordpress Plugin to for moving home page slideshow?
wordpress
I wonder how I can link manually to the smallest filesize for <code> the_post_thumbnail() </code> within its filter function … <code> add_filter( 'post_thumbnail_html', 'post_thumbnail_html', 10, 3 ); function post_thumbnail_html( $html, $post_id, $post_image_id ) { $html = '&lt;a href="' . get_permalink( $post_id ) . ...
Since you already know your $post_image_id, you can use wp_get_attachment_src() <code> $small = wp_get_attachment_src($post_image_id, 'smallest-size'); $large = wp_get_attachment_src($post_image_id, 'full'); $smallURL = $small[0]; $largeURL = $large[0]; </code> where 'smallest-size' is the name of the image-size you ha...
Filter for post_thumbnail: link to small src and add data-attribute
wordpress
I have multiple stage process that integrates complex faceting into WP queries. Problem is - the deeper I get the more fuzzy I become on how it is supposed to work and I could use a guideline rather than being inventive (and digging myself a hole). General stages I have (pseudo-code, but close to real): retrieve value ...
I think the WP function you are looking for is add_rewrite_tag . It aims to add custom GET params to your URL and include it automatically in <code> query_vars </code> . For example, you can add the following to the init hook : <code> add_rewrite_tag('%person%','([^&amp;]+)'); </code> For a url like http://example.com?...
What is appropriate flow for custom data from URL in WP_Query?
wordpress
I'm using wp_mail filter function. <code> add_filter('wp_mail','check_the_mail_content'); </code> If my condition satisfied then the mail should go, otherwise I need to stop, my function is <code> add_filter('wp_mail','check_the_mail_content'); function check_the_mail_content($query){ if(mycondition){ //mail should go....
Filter <code> 'phpmailer_init' </code> , not <code> 'wp_mail' </code> . To prevent sending the mail out reset the PHPMailer object. Prototype (not tested): <code> add_action( 'phpmailer_init', 'wpse_53612_conditional_mail_stop' ); function wpse_53612_conditional_mail_stop( $phpmailer ) { ! my_condition() and $phpmailer...
How to stop the wp_mail function?
wordpress
The default is singular, e.g. <code> http://example.com/category/apple/ </code> But I am wondering if it is better to use the plural form, e.g. <code> http://example.com/categories/apple/ </code> Are there any guideline on this?
There's a simple rule that I follow (it's hard to explain, so I'll give examples): <code> http://example.com/categories/ </code> &lt;-- This plural form should mean that the page shows a list of all the categories in use on your site. Similarly, if it's "authors" (as in <code> http://example.com/authors/ </code> ), I'd...
Permalink format: singular or plural
wordpress
I have a test site installed on www.mydomain.com/testsite. The problem I have is that if I type in the url www.mydomain.com/testsite/about I get redirected to www.mydomain.com/about. My page for my test site gives me the permalink: www.mydomain.com/testsite/about If I click View Page from the page editing screen in the...
Your htaccess file seems to be a little off. I would suggest the first part of the file should look like the following... <code> &lt;IfModule mod_rewrite.c&gt; RewriteEngine On RewriteBase /testsite/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /testsite/index.php [L] &lt;/IfMod...
Test site pages go to main site
wordpress
I lifted the "continue reading" link functions from the Twenty Eleven theme and for the most part, it is working (works in RSS feeds). I created a shortcode to display the latest post on the front static page using <code> get_posts </code> , however, the "continue reading" link just links to the front page instead of t...
<code> function gavsiu_recent_posts( $atts ) { extract( shortcode_atts( array( 'cat' =&gt; 3, 'max_posts' =&gt; 1 ), $atts ) ); $recent_posts = get_posts( array( 'category' =&gt; "{$cat}", 'numberposts' =&gt; "{$max_posts}", 'offset' =&gt; 0 ) ); foreach($recent_posts as $post) : setup_postdata($post); $permalink = ' &...
get_posts displaying wrong permalink for "continue reading" link
wordpress
After finding a couple of leads on how to do this, I'm coming up blank. What I am trying to accomplish is to add the post to a new category based on camera name. If the category doesn't exist, then to create it and add. Essentially what I have below grabs the attachment meta information and saves the camera information...
First, some comments on your code: the globals <code> $post </code> and <code> $wpdb </code> are not needed, in any case you can declare them as <code> global $post, $wpdb; </code> I don't understand your use of this conditional <code> if (is_null($imgID)) </code> you're using <code> get_term_by </code> with "slug", bu...
Create new category upon save based on post information
wordpress
I am using an Options Panel to create my themes, and I would like to make the textareas from this OP to support my shortcodes too. The code for that creates the textarea fields: <code> case 'textarea': $cols = '8'; $ta_value = ''; if(isset($value['options'])) { $ta_options = $value['options']; if(isset($ta_options['col...
simply use <code> echo do_shortcode($textarea_value); </code> (answer by @Bainternet)
Shortcodes in Options Panel textareas
wordpress
I am building a theme and for the Theme Settings Page I followed this tutorial: http://wp.tutsplus.com/tutorials/using-the-settings-api-part-1-create-a-theme-options-page/ What I want now is to have a multi-checkbox with every category. This is what I should have: <code> $options[] = array( "section" =&gt; "zzz", "id" ...
Thanks Michael for the tip. I finally got it. The solution is as follows: <code> $options[] = array( "section" =&gt; "zzz", "id" =&gt; HS_SHORTNAME . "_multicheckbox_inputs", "title" =&gt; __( 'Multi-Checkbox', 'hs_textdomain' ), "desc" =&gt; __( 'Some Description', 'hs_textdomain' ), "type" =&gt; "multi-checkbox", "st...
Get categories names as an array to use it in theme settings
wordpress
In a theme I'm building, I have this structure for detecting what type of page something is. However, if I visit mydomain.com/category/ or mydomain.com/tag/, all I get is the "nothing found" message I have in the have_posts()'s else statement. Is there a way to detect when these links are visited and display something ...
If I put this above the htaccess block of wordpress rules, I'm able to redirect the tag and category base pages back to the homepage. <code> RewriteCond %{HTTP_HOST} ^mydomain.com$ [OR] RewriteCond %{HTTP_HOST} ^localhost$ RewriteRule ^category/?$ "http://mydomain.com" [R=301,L] RewriteRule ^tag/?$ "http://mydomain.com...
How to detect /category and /tag base pages?
wordpress
I want to add custom button "Send for correction" somewhere near the "Publish" button. This custom button must change a post status from "Pending" to my own created status named "On correction". For a now it is possible to change status with 5 clicks (Edit status -> Dropdown click -> Select On-correction -> Ok -> Save ...
You can create your custom button in a function and hook it into <code> post_submitbox_misc_actions </code> and this will add it right above the publish button. To change the status use wp_update_post in an Ajax function. Give it a try and post back with your code if you run into any problems. UPDATE: <code> add_action...
Changing post status in one click
wordpress
I have a custom field added through the Advanced Custom Fields Plugin. I am trying to trim the content of the field down to a set number of words. I have tried to use the excerpt filter and setting a custom length see code bellow but It's not working, thought? <code> // set the length of the excerpt function custom_exc...
The excerpt is a specific field in WordPress and is wholly unrelated to custom fields, which is why the excerpt stuff you tried has no effect. There is no built in way to trim custom fields, you have to do it manually with a bit of php: <code> $length = 20; $text = 'Lorem ipsum dolor sit amet, consectetur adipiscing el...
Trimming a custom field to a length
wordpress
I'm manually creating users programmatically, and I want to sign in the newly created user. WP makes it easy to access the hashed password, but not the plaintext version. Is there a way to use wp_signon() without the plaintext password? I found one person who claims to have done this here , but it didn't work for me. T...
<code> wp_set_auth_cookie() </code> will log a user in without having to know their password.
Can I programmatically login a user without a password?
wordpress
Using this on my index.php <code> &lt;?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?&gt; </code> Using plugin: WP-PageNavi Wp Pagenavi Style Not sure what information you need to help me fix this. So please let me know. Site: http://www.slashgeek.net/ edit: code of index.php http://pastebin.com/hThDBcyC
I took a look at the index.php code and I'll explain what's going on. The theme author is using 2 custom new WP_Queries but is not doing anything with the main global $wp_query object. When you click to the second page you get the same posts because there is no main loop present. Neither of the secondary loops contain ...
pagenavigation not showing the next page just linking back to the main page
wordpress
My friend asked me to activate a site that someone else did it. The problem is that when I try to run it, and I go to <code> mysite.com </code> I arrive to <code> mysite.com/wp-login.php?redirect_to=/ </code> Where and how can I fix it?
disable all plugins or change theme to default one. AFAIK there is no such function by default in WP to redirect non loged in users to login page.
How to cancel redirection to admin side
wordpress
I hope someone can help me. I have a root installation of WP, but not as <code> index.php </code> (it's actually <code> news.php </code> ). Consequently <code> the_permalink() </code> doesn't work, as the root of the website is a different page. Is there any way I can fix this? Perhaps something in the .htaccess that d...
Change the name of news.php to index.php. I don't know of any legitimate use case that exists for changing index.php. If something else is using index.php then move WP in its own /news directory. You could change the .htaccess but you might run into trouble down the road.
the_permalink() not working in a root installation
wordpress
I'm writing a Wordpress plugin. The plugin should allow every user to rate posts (1 to 5 stars). What actually works is to read the rating from storage and show the stars. So there are five <code> &lt;a&gt; </code> links after every post, indicating the ranking by different colours. The stars are linked because I want ...
You could, feasibly, do it with a custom field , ignoring ajax. You could store the ratings of each one in an array in the field. The star rating would be generated something like this: <code> //note this is untested and provided as a guide not gospel $ratings = get_post_meta($post_ID,'star_ratings'); $total = 0; forea...
Wordpress Plugin Receive a Link
wordpress
I'm trying to control the output of the random image within this bit of code. The end goal is to NOT output the <code> width </code> and <code> height </code> attributes for the image. I want this: <code> &lt;img src="URL HERE" alt="ALT HERE"/&gt; </code> BUT I DON'T WANT THIS (which is what the code below currently ou...
Use <code> wp_get_attachment_image_src() </code> and build a simplified <code> img </code> element. You may use something like the following code as a replacement for <code> wp_get_attachment_image() </code> : <code> function wpse_53524_get_image_tag( $attach_id, $size, $icon, $alt = '' ) { if ( $src = wp_get_attachmen...
Prevent Width and Height Attributes in Image Tag Output
wordpress
I am trying to update a users role based on number of posts published when the user publishes a new post. I have tried this code but it does not work. <code> add_action('publish_post', 'update_roles'); function update_roles() { global $wpdb; // Get the author $author = wp_get_current_user(); $posts = $wpdb-&gt;get_resu...
<code> current_user_can() </code> checks for a capability , eg: edit_posts, not a role. The only capabilities subscribers have is read which only gives them access to the dashboard to change their profile (unless you added additional caps) . They can't even publish a post so you will have to start with contributors. <c...
Update a users role based on number of posts published
wordpress
How to display user role on author page. I have created my own role (group) so I want to display the user role on below the post and on author list. I have tried this code but not working as its calling current_user and its showing current user role in all authors profile <code> &lt;?php $user_roles = $current_user-&gt...
Change: <code> $user_roles = $current_user-&gt;roles; </code> with <code> $user = new WP_User( $user_id ); $user_roles = $user-&gt;roles; </code> and the $user_id should e the actual user id who's role you are trying to get. Update, Sorry i just read the author template part so try this: <code> //first get the current ...
How to display user role
wordpress
I'm not sure how to word my question and I have been searching all day, to no avail. I am looking for a method to create two versions of my RSS feeds, one with the full content and one with only the excerpt. Mainly, I want to do this for the "Author" feeds. I would like two feeds created for each Author. One with the f...
My approach would be to: On the Reading Options page, set the <code> For each article in a feed, show... </code> option to <code> Full Text </code> so that, by default, feeds will include the entire post. Pass a custom URL parameter to each individual feed when you want the excerpt instead of the full text. e.g., <code...
Multiple versions of RSS feed? One with full content, one with the excerpt
wordpress
I'm working with this code snippet for an "on this day" type post. However it is only showing 1 year in the past. I'm looking to automate this so it shows on this day in 2009, 2010, 2011... and as the years advance, keep these years showing. With the way it's written as a -1, -2, it will be a dynamic "year ago" rather ...
I took the code provided by the answer from @moraleida and improved it so that it would look at the post dates, and not the server dates. I also modified it so that it would look for all posts on that post Month and Day, and link to them as long as it's not the same post ID that's being displayed on. Afterall, since yo...
On this day PHP code
wordpress
I'm using a photoblog theme which upon creating a new post it takes the post attachment and saves a modified "img src" string into the excerpt field. It then uses <code> &lt;?php the_excerpt(); ?&gt; </code> to display the thumbnail on pages like homepage menu, category pages and tag archives. My website has a few hund...
Issue 1: creating the excerpt data This should be fairly easy to do directly with SQL. <code> UPDATE wp_posts AS post INNER JOIN wp_posts AS attachment ON attachment.post_type = 'attachment' AND post.ID = attachment.post_parent SET post.post_excerpt = CONCAT('&lt;img src="', attachment.guid,'" /&gt;') WHERE post.post_e...
Mass update excerpt
wordpress
I've created a plugin, and it has a function that takes two args, like so: <code> process($tokens, $payloads); </code> ... would this work? : <code> add_action ( 'publish_post', process($tokens, $payloads) ); </code> Many thanks!
No, this cannot work. Haven't you tested your idea? A simple workaround would be a class: <code> class WPSE_53453_Action_Handler { public $tokens, $payloads; public function process() { $tokens = $this-&gt;tokens; $payloads = $this-&gt;payloads; // do something awesome } } $WPSE_53453 = new WPSE_53453_Action_Handler; $...
Running a function with args in add_action()
wordpress
I'm trying to display a table of results for particular users who have submitted answers to quizzes. The problem is that the mysql database I am working with has a funky value for the user's ID. I'm working off of the plugin WP Simple Survey , which allows the admin to create a number of surveys and weight answers with...
The plugin now works as I would like, with a little alteration. Instead of setting submitter_id to a random value, it is now set to the logged in user's id. This will allow displaying other users' answers. The + indicates new lines of code in the output_quiz.php file: <code> function wpss_getQuiz($quiz_id){ global $wpd...
How to display results from a data table with an encrypted user id?
wordpress
I read on the codex that the best way to implement a clean uninstallation functionality to a plugin is by adding a uninstall.php file inside your plugin directory. I'm wondering: can i use my plugin's Class instance data inside the uninstall.php file? This is the code sitting in my uninstall.php file: <code> if(!define...
I'm not in my desktop, but I suspect it won't be retrieved. But: have you tested it? Does the table gets droped? I'd say you need to declare global $wpdb; , isn't it? if you don't have any, a tool like FirePHP is really handy when developing anyway, this seems a case where is pretty harmless to hardcode the table name
Does plugin's uninstall.php file have access to the plugin 's object?
wordpress
I dont understand why my sidebar isn't changing over to the second one on the other pages. I've gone in an told the pages that if your not on this page show sidebar 2. So the home page and blog page have a sidebar 1 and the rest of the pages have sidebar 2. But it's not working. My code on my main theme layout looks li...
Your main problem is that the <code> is_page() </code> conditional will not return true if it is included inside or after the loop. Your other issue which is not necessarily related to the issue at hand is the way you are including your sidebars. WordPress comes with a handy little function called <code> get_sidebar() ...
Different sidebars not changing
wordpress
I'm trying to find a template page (or conditional statement) that will target: http://url.com but not http://url.com/page/2/ home.php and front-page.php seem to target both. The front page displays my latest posts. Thanks in advance!
WordPress provides <code> is_paged() </code> which returns true on any archive or blog that stretches over multiple pages. This isn't what you want, but the <code> is_paged </code> Codex article tells us where to go: If you need to check which page of the blog you are on, you can look in $wp_query-> query_vars['paged']...
Template tag for /page/# structure
wordpress
I a using an image carousel to display some pictures on my website. The carousel I am using is called: Jcarousellite ( http://www.gmarwaha.com/jquery/jcarousellite/ ). I have the carousel setup, styled, and configured...but am having trouble getting through the last little bit of the code to work. The code I am using t...
I ended up just using a lightbox instead, it was super-easy to implement and looks great!!
Carousel Hover Image
wordpress
I have tried two Rotator plugins so far. Nivo-slider and EasyRotator. Nivo-slider was great, but i could only have an image caption, and i need both image caption and image title. Also, i couldn't get the "bullets" for indicating the current slide to work. So i Googled and found the "EasyRotator"-plugin. Great, except ...
Content Slide can handle that. http://wordpress.org/extend/plugins/content-slide/ And the plugin site: http://www.snilesh.com/resources/wordpress/wordpress-plugins/wordpress-content-slide-plugin/ It's a champ and handles all three of your conditions. 'Bullets' are square, you can mod that though. Have fun!
Image rotator plugin
wordpress
I'm having trouble only adding scripts to single post pages. I need to both include and exclude certain scripts using is_single() but it doesn't work either way I try it. I have the template tag on the top of custom single post templates... <code> &lt;?php /* Template Name: Single Default */ ?&gt; </code> And I use thi...
This could be one of a few different issues. 1. Wrong Hook / Not Hooked You need to make sure that <code> wp_enqueue_script </code> is hooked to <code> wp_enqueue_scripts </code> . Otherwise, the call can get fired too late or (possibly in this case?) too early? Try this (also with your php cleaned up a bit: <code> fun...
Problem using is_single() to enqueue script from functions.php
wordpress
I'm working on revamping my personal blog with a custom built theme and making it bilingual with the help of qtranslate. I've gotten to a grinding halt when it comes to automatically generating the shortlinks (offered for analytics reasons). Up till now, I got the following code, based on Kovshenin's goo.gl plugin , th...
So I've managed to solve this. The <code> googl_shortlink </code> function from above now looks like this: <code> function googl_shortlink($url, $post_id = false) { global $post; if (!$post_id &amp;&amp; $post) $post_id = $post-&gt;ID; elseif ($post_id) $post = get_post($post_id); // list all the active languages in an...
Generate multiple goo.gl shortlinks for qtranslate bilingual blog
wordpress
I would like that every time any plugin previously activated, a function from my plugin be called, returning (at least) the name of the plugin, or something that allows to identify it (file name?). I figured i could use the action hook "deactivated_plugin" but i'm wondering what information from the desactivated plugin...
You can hook into the action <code> 'deactivate_plugin' </code> to get the plugin's base name and (as second parameter) if it was deactivated network wide. See <code> wp-admin/includes/plugin.php function deactivate_plugins() </code> . There seems to be no hook for plugin deletion. Sample logging code: <code> add_actio...
deactivated_plugin hook: get the name of the plugin
wordpress
I checked out (with svn) the code for Automated Testing . However, I want to run unit tests as a specific user. Is there a way to do that? That is, is there a way to loggin with php code alone?
<code> $user_id = $this-&gt;_make_user('author', 'user_login_name', 'password', 'test@test.com'); wp_set_current_user( $user_id ); </code> as long as the class that you define the testcase in inherits from <code> WPTestCase </code> , then you can use the <code> _make_user </code> function. The function is found in this...
automated tests as a user?
wordpress
How can I remove the "bulk actions" based on user roles or capabilities. Actually I have this code to do the job, but now I need to exclude the site admin, I need to let the administrator to access the bulk menu <code> add_filter( 'bulk_actions-' . 'edit-post', '__return_empty_array' ); add_filter( 'bulk_actions-' . 'u...
I would do this this way - Just add a new mu plugin or normal plugin: <code> &lt;?php defined( 'ABSPATH' ) OR exit; /** Plugin Name: Limit Bulk actions to Editor &amp; Admin */ add_action( 'wp_loaded', 'wpse_53371_remove_bulk_actions' ); function wpse_53371_remove_bulk_actions() { if ( ! is_admin() ) return; if ( ! cur...
Remove bulk actions based on user role or capabilities
wordpress
I'm looking for a plugin that would keep track of a all the structural "changes" journal. For instance, the date+time of each wordpress upgrade, or plugin install/update/activation/desactivation or desinstallation, along with the plugin version. Do you know of anything related?
With the help of @toscho, i made this plugin http://wordpress.org/extend/plugins/wp-changes-tracker/
A Blog's changelog
wordpress
I am trying to make things work like where author can see only them post comment in admin comment section and they can moderate as well. While admin should have all permission. I am having one code and working fine in all terms like showing only author's post comment but it's not allowing to moderate. Can anyone help m...
The default author role does not have the <code> moderate_comments </code> capabilities so you need to add that capability to the author role, so add this to your plugin: <code> function add_theme_caps() { $role = get_role( 'author' ); // gets the author role $role-&gt;add_cap( 'moderate_comments' ); // would allow the...
Author can only see own post comment and can moderate
wordpress
I have a custom post type that describes components of a product. As the product is developed new components are added. I'd like to define what version of the product the component was added, and then be able to browse products by that version. I tried making a custom taxonomy as the version, but my problem is when I b...
Taxonomies is not the right approach here, you should use custom fields (post meta) instead this way you can use <code> compare </code> argument of the meta query as <code> &lt;= </code> ex: <code> $args = array( 'post_type' =&gt; 'product', 'meta_query' =&gt; array( array( 'key' =&gt; '_version', 'value' =&gt; '1.0', ...
Custom taxonomies to define versions of a product
wordpress
I'm building a site with a lot of widgets. They have been highly customized. Several admins/editors will have to edit these widgets when the site is live. Right now I'm scared to see a widget (and its configuration) can be fully erased in a single mouse move (dropping it off the side bar). Is there any way to prevent w...
The solution I can think of is removing the panels Available and Inactive Widgets so there's simply nowhere to drag (and delete) the widgets used in the sidebar. You can inject something else to fill the gap. In this example, only one user is able to add/delete widgets. <code> function wpse_53398_script_printer(){ // u...
Prevent widgets removal
wordpress
i need to now what is name of this plugin that's used for image gallery page in this site
According to the document source, the site is loading scripts from the NextGen Gallery Plugin .
what is name of this plugin used for photo gallery page
wordpress
I have installed the Recent Posts plugin, that came with a widget. Now, i can only add one instance of the widget to the widget areas. I want one instance to show in my widgetarea that only appears on my startpage, and one instance of the widget to my widgetarea that appears on other pages. Now, the widget doesnt seem ...
Easy, Anton! You don't have to hack the database... Probably you can find a replacement for this plugin that uses the modern Widgets_API , responsible for the multi-instance widgets. At least as far as I know, because haven't worked much with WordPress pre-2.8. If you are willing to hack something, hack the plugin usin...
Recent Posts+, how to solve multiwidget?
wordpress
Is there a easy way to do that? Godaddy have a silly limit of 1024 files in one folder and my client upload more than 500 and with the thumbnails we get lot over the limit. If im able to changed folders into %year%/%month%/%day% i will be safe about that limit Also another question is if i can make wordpress to generat...
The Custom Upload Dir plugin can help with this. For a teaser, they've got a screenshot of someone defining an upload behaviour which is similar to the one you're asking for:
how can i simple change upload folders to %year%/%month%/%day%?
wordpress
I am trying to setup a wordpress slider, how can I achieve exact below result within a wordpress loop <code> &lt;div id="carousel"&gt; &lt;img src="slide1.png" alt="" class="slide" /&gt; &lt;img src="slide2.png" alt="" class="slide" /&gt; &lt;img src="slide3.png" alt="" class="slide" /&gt; &lt;/div&gt; &lt;ul id="carou...
Use <code> rewind_posts() </code> to reset a loop and run it multiple times: <code> &lt;?php $my_query = new WP_Query('cat=49&amp;showposts=4&amp;orderby=RAND'); ?&gt; &lt;div id="carousel"&gt; &lt;?php while ($my_query-&gt;have_posts()) : $my_query-&gt;the_post(); // output each slide endwhile; ?&gt; &lt;/div&gt; &lt;...
Specific html within wordpress loop
wordpress
I am looking for a way to output some html (javascript actually) on a post view only and not on a main page, tag, category view (where WP outputs several posts). E.g it would be output on this page blog.yourdomain.com/2012/05/some-post/ But not on blog.yourdomain.com/ blog.yourdomain.com/category/xxx/ blog.yourdomain.c...
Eugene's answer was a little over complex for my needs so here's what I did (though +1 to Eugene as it got me looking in the right places) I first added a custom field called singlePostHTML to the posts that I wanted to add script to - put the script in the value. Wordpress - Using Custom Fields I then edited single.ph...
Output HTML only on individual post view
wordpress
I am using the Woocommerce plugin to facilitate a small e-commerce part of a site and need to add products to it's cart via some call or function rather than using it's own 'add-to-cart' buttons. By this I basically mean send Woocommerce a SKU and quantity for example and have the cart update. <code> sendToCart('123456...
OK so here's how I solved it in the end. A quick and dirty example, uses JQuery. <code> &lt;a id="buy" href="#"&gt;Buy this!&lt;/a&gt; &lt;script&gt; $('#buy').click(function(e) { e.preventDefault(); addToCart(19); return false; }); function addToCart(p_id) { $.get('/wp/?post_type=product&amp;add-to-cart=' + p_id, func...
Woocommerce - Add a product to cart programmatically via JS or PHP
wordpress
This code isn't echoing out anything, even though I'm 100% positive $mixtape_id is set to an integer which corresponds to one of the posts within the 'mixtapes' custom post type <code> $query = new WP_Query(array( 'post_type' =&gt; 'mixtapes', 'p' =&gt; (int)$mixtape_id, 'posts_per_page' =&gt; -1, 'orderby' =&gt; 'meta...
I fixed it by doing it a different way <code> $query = new WP_Query(array( 'post_type' =&gt; 'tracks', 'posts_per_page' =&gt; -1, 'orderby' =&gt; 'meta_value_num', 'meta_key' =&gt; 'track_number', 'meta_query' =&gt; array( array( 'meta_key' =&gt; 'mixtape', 'meta_value' =&gt; (string)$mixtape_id ) ) )); </code>
WP_Query with custom post type ID
wordpress
My profile is set to show the WP toolbar when viewing the site, but on a page using the front-page.php template the toolbar space is reserved but its contents are not visible. What could be the reason for this?
I had not included <code> wp_footer() </code> . It seems the code for the toolbar is included with this call, and <code> wp_head() </code> . Modifying the Toolbar Reasons Why Your Toolbar May Not be Showing
toolbar not visible on pages using front-page template
wordpress
I need to edit a list of quotes. Every quote consists of a (short) text, author's name, author's title. What is the best way to create an editor of such data in WordPress? It seems that the simplest solution is to create a custom post type. Should the quote text become the title of a post? (It is not quite the title, l...
I would build a custom post type. Use the editor to hold the quote in the site's default language and create a new box to hold the translated version. A second meta box can hold the author's name and title. For the post title, just use something descriptive, so that you can find the post later on for editing. When you ...
Editing a list of several fields
wordpress
I added a .htaccess file to a wordpress website I'm working on, to show nice urls instead of page ids. The content of the .htaccess is this: <code> &lt;IfModule mod_rewrite.c&gt; RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] &lt;/IfMo...
Your problem has nothing to do with htaccess. It's that you're using relative paths where you should be using absolute paths. ( Here's an explanation of the difference ) Probably the best way to reference any assets in your theme (assuming your theme has an "images" subdirectory) is to do something like: <code> &lt;?ph...
Images in sub-pages fail to load
wordpress
why if im add size like : <code> add_image_size( 'featured1', 466, 316, false); add_image_size( 'featured2', 466, 260, false); </code> the seconde size Does not generated What is the problem ?
Probably because your sizes both have the same width, and you have it set to "proportional crop", which won't necessarily crop to your exact dimensions. ( See the Codex ) In all likelihood, it is actually creating both images--but they're both the exact same size, so one overwrites the other :) Try changing the last pa...
problem with add_size_image
wordpress
<code> $term_id .= $_POST['main_brand_id']; $term = get_term( $term_id, 'state' ); $slug = $term-&gt;slug; global $post; $args = array( 'post_type' =&gt;'dealers','taxonomy'=&gt;'state', 'term' =&gt; $slug ); $myposts = get_posts( $args ); foreach( $myposts as $post ) : setup_postdata($post); echo '&lt;option&gt;'; $op...
<code> $post-&gt;id </code> needs to be <code> $post-&gt;ID </code> You can also use <code> get_the_ID() </code> Since your calling <code> setup_postdata() </code> you need to call <code> wp_reset_postdata() </code> after your foreach loop. You also need to echo the value of $options somewhere. <code> foreach( $myposts...
how to get the post id in the option tag
wordpress
I am using the following code to list the child pages of current page on my sidebar. It is working very well. <code> $titlenamer = get_the_title($post-&gt;post_parent); $output = wp_list_pages('echo=0&amp;depth=1&amp;title_li=&lt;div id="list-title-head"&gt;'.$titlenamer.'&lt;/div&gt;' ); if (is_page( )) { $page = $pos...
I would try replacing your <code> $children </code> definition, using <code> get_page_children() </code> or <code> get_children() </code> : <code> &lt;?php global $post; $children = get_children( array( 'post_type' =&gt; 'page', 'post_parent' =&gt; $post-&gt;ID, 'post_status' =&gt; 'publish' ) ); if ( $children ) { // ...
How to control display of page lists on sidebar that doesn't have childrens
wordpress
I'm after either a plugin suggestion or code suggestion that best handles images per post. Here's the scenario, every post could have up to 6 images, all to be assigned class names etc. All to be displayed on single.php. I'd like to be able to choose one of those 6 images that I'd like to display as a large image withi...
I'd like to be able to choose one of those 6 images that I'd like to display as a large image within the same template file. This would probably fit as the Post Thumbnail/Post Featured Image . Additionally, out of these 6 images I'd like to randomly call in 1 random one on to a custom page template in another loop else...
Multiple images per post - Show random image elsewhere
wordpress
I want to setup my WordPress so that whenever I create a post with the category "Tweet", my wordpress installation automatically changes the post format from post to aside. This will help me because I want to use my wordpress for posting longer than 140 tweets to my twitter feed. The posting to twitter has been setup a...
Try putting this plugin in your <code> wp-content/plugins </code> folder and then activate it: <code> &lt;?php /* Plugin Name: WPSE53245 - Set Tweet category posts as Aside Plugin URI: http://stackexchange-url Set Tweet category posts as Aside Version: 0.1 Author: Ashfame Author URI: stackexchange-url add_action( 'save...
Plugin to set all Posts in a certain Category to a certain Post Format
wordpress
Is it possible to intercept calls to current_user_can() ? Example: <code> current_user_can('rate', $post_id) </code> There's no "rate" capability registered, but could I somehow hook into that function and do my own checks, without having to register a role capability?
Yes, just filter <code> 'user_has_cap' </code> . You get an array with the current capabilities that you can change without touching the database. Sample Code <code> add_filter( 'user_has_cap', 'wpse_53230_catch_cap', 10, 3 ); /** * See WP_User::has_cap() in wp-includes/capabilities.php * * @param array $allcaps Existi...
Temporary capability for current_user_can()
wordpress
I thought I was making my life easy and being future-conscious by saving some content as bits of JSON in custom post_meta fields. Unfortunately, WordPress doesn't agree and is making my life incredibly difficult. I have a JSON string that looks essentially like this. This is just one bit, and the comment string is just...
Doesn't look like there's any way to avoid it. The update_metadata() function, which is ultimately responsible for saving the meta, explicitly runs a stripslashes_deep() on the meta value. This function will even strip slashes from array elements, if the value were an array. Theres a filter that's run AFTER that called...
WordPress is stripping escape backslashes from JSON strings in post_meta
wordpress
I'm trying to make a small plugin to install in some sites of a german client. I can make my way around WordPress in german, but would be easier if it was in english. There's a plugin that manages this (WP Native Dashboard) and albeit it does it wonderfully, it's too heavy weight to what I need. The client don't need t...
Ok, finally got to the core of WP Native Dashboard basic concept and it's working now. The file is being used as a <code> mu-plugin </code> , and whenever I have to work in the site I rename it from <code> set-user-locale.phpa </code> to <code> set-user-locale.php </code> , and then back again. Thus activating and deac...
Change admin language based on user (in single-site)
wordpress
How can I create let say 3 posts after the user finish the registration ? The ideal outcome would be to create 3 posts using the user as the author of the posts and with some pre-defined values. (post title and slug) The post title and slug would be created from info that the user will provide on the registration form....
You kind of answered the question yourself already, Create a function that will create the 3 posts ex: <code> function create_new_user_posts($user_id){ if (!$user_id&gt;0) return; //here we know the user has been created so to create //3 posts we call wp_insert_post 3 times. // Create post object $my_bio_post = array( ...
Create posts on user registration
wordpress
tl;dr: Contact Form 7's shortcode doesn't work in an AJAX request when called with <code> do_shortcode </code> functions.php <code> add_action('wp_ajax_ps_get_survey_form', 'ps_get_survey_form'); add_action('wp_ajax_nopriv_ps_get_survey_form', 'ps_get_survey_form'); function ps_get_survey_form() { echo do_shortcode( '[...
The answer is to sidestep admin-ajax restrictions by handling it yourself, as @OneTrickPony suggests. <code> add_action( 'init', function() { ps_register_shortcode_ajax( 'ps_get_survey_form', 'ps_get_survey_form' ); } ); function ps_register_shortcode_ajax( $callable, $action ) { if ( empty( $_POST['action'] ) || $_POS...
Why might a plugin's 'do_shortcode' not work in an AJAX request?
wordpress
I'm trying to grab all posts which are 'posts' and not in category '3' and '5' and which aren't 'pages'. Is this possible to do using one single <code> get_posts() </code> ? Because I'm querying both actual posts and pages at the same time...
The <code> get_posts() </code> function only returns one post type at a time . So if you query for <code> 'post_type' =&gt; 'post' </code> , by default you won't get any Pages returned. This should work: <code> &lt;?php $wpse53292_posts = get_posts( array( 'post_type' =&gt; 'post', 'exclude' =&gt; array( 3, 5 ) ) ); ?&...
Use get_posts() with 'post' and 'page' queries at the same time?
wordpress
I setup a custom post type for my portfolio projects. The main URL for this is located at /projects/ Now I've also setup my blog posts permalink to /articles/*/ for the permalink structure. This means when I go to view a portfolio project the URL changes to /articles/projects/project-name/ I know there must be a way to...
When you register the custom post type, you have to specify that the rewrite rule shouldn't be prepended with the existing URL structure. In short, this means that this line in your <code> register_post_type </code> call: <code> 'rewrite' =&gt; array('slug' =&gt; 'projects'), </code> should turn into this: <code> 'rewr...
Custom Post Type URL Rewriting?
wordpress
I had links like <code> example.com/?location=boston </code> on my site. These were indexed by Google. Due to obvious SEO reasons, I had to change the URL structure to <code> example.com/deals/boston </code> . The old URLs are there on Google results and redirect correctly to new URL. What I want to know is: while doin...
Really depends on how your redirects are set up. But you can check the status code using Firebug (or a comparable tool with a request profiler). Open up the "net" tab in firebug, and hit one of your old URLs. You should** see the request show up at the top of the list, and you'll see the response code in the "status" c...
Redirecting to new URL structure and 301
wordpress
I have the following function, I need to exclude categories from it because it works across the site in several different places. How can I do that? <code> // allCategories(): return an array of categories to browse in heirarchy public function allCategories() { $return = array(); if ($this-&gt;category) { $return = $t...
In case it helps someone else, this was a much easier fix than I thought. I simply added the category ids to exclude to the query_posts argument, e.g., <code> query_posts("s=$s&amp;cat=-415,-504&amp;posts_per_page=-1"); </code>
exclude categories from search results
wordpress
I have 1000 images. How can i make wordpress to generate thumb only when needed. For example home slider will only use 10 images i dont want the other 1000 images have that thumbnail generated as its a waste of space and resources. There is a way to fire add_image_size only when needed ? Thanks UPDATE As you mention is...
Take a look at Otto's Dynamic Image Resizer plugin This plugin changes the way WordPress creates images to make it generate the images only when they are actually used somewhere, on the fly. Images created thusly will be saved in the normal upload directories, for later fast sending by the webserver. The result is that...
How to generate thumbnails when needed only?
wordpress
I can't find any info on how to operate qtranslate and add the select box to change language to the right of my header navigation. Any ideas?
In my header.php I added the following <code> &lt;div style="float: right; margin: 7px 15px 0 0;"&gt; &lt;?=qtrans_generateLanguageSelectCode('dropdown');?&gt; &lt;/div&gt; </code> <code> &lt;?=..?&gt; </code> is the same as <code> &lt;?php echo ... ?&gt; </code> or <code> &lt;?php function(); ?&gt; </code> , but I pre...
Add qtranslate language select box to menu
wordpress
If I make an ajax call to a Wordpress transient, is the transient value taken from memory on the server or is a call to the database made? I'm not using any caching plugins. My application is fetching a tag list. The frontend will display matching tags as the user types. I'm assuming that all transients are loaded when...
Without object caching plugins transients are stored using options API and, if set to expire, they have auto-load disabled. Meaning: First request to transient needs to fetch it from database. Subsequent requests will get data from memory. However note that "memory" here is memory space of single specific page load . I...
Ajax call to transients
wordpress
I have an array of IDs that i send to query_posts to get the posts (which works fine) but it seems to always put the attachment(562) last even though it is the newest. Also tried title and ASC vs DESC but its always last? <code> $slide_args = array( 'post_type' =&gt; 'attachment', 'post_status' =&gt; 'inherit', 'fields...
I think I got it. You're querying for sticky posts. Attachments can't be sticky at least by default. Hence, you're see the normal loop order when sticky posts are involved. So if you add this to your second args array: <code> 'ignore_sticky_posts' =&gt; true </code> I think your problem should be resolved. Here's the r...
orderby not working for query_posts using array of IDs
wordpress
I've been reading alot about how to order posts by a <code> meta_value </code> , but I can't seem to get it to work for me. My <code> meta_key </code> is called <code> date </code> , and it is stored as <code> yyyy-mm-dd </code> . Here's where I've gotten to so far: <code> $args = array( 'posts_per_page' =&gt; -1, 'met...
So I figured out how to get what I want, but it's still not perfect. The problem revolved around how my custom meta value was being stored - basically as a string. I needed to tell MySQL that it was a date, so it could be used to order the posts. To this end, I used a custom query: <code> $posts = $wpdb-&gt;get_results...
order posts by meta value on posts page
wordpress
Due to a complex multisite config, I have a query which combines the posts from two blogs and I would like to paginate the results . I am grateful for any help. I have posted my query. <code> $latestposts = $wpdb-&gt;get_results( " (SELECT * FROM net_5_posts INNER JOIN net_5_term_relationships ON net_5_posts.ID=net_5_t...
Update I've tested this and it works on my site. A few things: Replace my <code> $query </code> with yours <code> global $wpdb </code> (per your comment regarding global variables) since it's out of scope! <code> get_results() </code> returns an object when not told otherwise (second parameter is the return type) I pla...
WordPress Paginate $wpdb-> get_results
wordpress
I have the following line in a register_post_type function: <code> 'rewrite' =&gt; array('slug' =&gt; 'Newsletters', 'with_front' =&gt; false), </code> I understand what the line does in general (adds "newsletters" to the slug) but I don't specifically understand what the 'with_front' part does. I have to admit, I don'...
From the Codex ... Should the permastruct be prepended with the front base. (example: if your permalink structure is <code> /blog/ </code> , then your links will be: false-> <code> /news/ </code> , true-> <code> /blog/news/ </code> ). Defaults to true
What is the "with_front" rewrite key?
wordpress
I purchased a Wordpress theme this week, and to keep my changes separate from the original theme, I created a child theme for it. Right now it's just a barebones child theme, the style.css file and screenshot. The parent theme has several CSS and jQuery scripts that it includes. The problem however is that the child th...
As this is a commercial Theme, you really need to contact the developer for support. That said: the Theme appears to be mis-using <code> get_stylesheet_directory_uri() </code> , when it should be using <code> get_template_directory_uri() </code> .
Child theme grabbing wrong location fo parent theme files
wordpress
Lets say I have the following Categories in Wordpress: Product Category - Cat A - Cat B - Cat C Service Type - Service A - Service B - Service C On the Manage Posts page on the Admin side, I want to have 2 drop down filters for both Product Category, and Service Type, so I can filter by both on the backend. How can I d...
I'd say it's quite a huge task to split the default taxonomy in two dropdowns. Maybe some wizard stumbles upon your question and enlighten us... The biggest problem I see is the split itself, because you can modify the query <code> &amp;cat=1 </code> to <code> &amp;cat=1,25 </code> so as to list two categories (by thei...
Wordpress - Admin Manage Posts - Multiple Filters by Parent Category
wordpress
How would I go about adding a unique class to the direct child li elements of the main parent ul element generated with wp_nav_menu? <code> &lt;nav id="access" role="navigation"&gt; &lt;div class="menu-main-container"&gt; &lt;ul id="menu-main" class="menu"&gt; &lt;li id="menu-item-30" class="menu-item menu-item-type-po...
Check out the section titled Adding Conditional Classes to Menu Items on the <code> wp_nav_menu </code> Codex page. This should give you a pretty good overview for adding classes to menu items using the <code> nav_menu_css_class </code> filter. For what you asked to do, which is add <code> menu_element </code> to the c...
Adding a unique class to wp_nav_menu
wordpress
I'm developing a WordPress based website. Using latest version of WordPress and Genesis theme. I've to use a seperate stylesheet for IE, how can I add that? Sorry for this silly question, I'm new in web development :(
Well, add these lines to functions.php of your theme. <code> add_action('wp_head','ie_only'); function ie_only(){ ?&gt; &lt;!--[if IE]&gt; &lt;link rel="stylesheet" type="text/css" href="&lt;?php echo get_bloginfo('stylesheet_directory'); ?&gt;/ie-only.css" /&gt; &lt;![endif]--&gt; &lt;?php } </code> Now create a css f...
IE and WordPress
wordpress
I created a page called Catalog and also a template called page-catalog.php. The url looks like this now: sitename.com/catalog So far so good, however i use some custom php stuff to list products from another database. So when i click on a brand in this page, i want to use an url like this: sitename.com/catalog/brands/...
You could use a WordPress rewrite (as opposed to mod-rewrite) to solve the issue. <code> function createRewriteRules( $rules ){ $newrules = null; $newrules = array(); $newrules["catalog/?$"] = "index.php?page=xx"; $rules = $newrules + $rules; return $rules; } add_action('rewrite_rules_array', 'createRewriteRules'); </c...
How can i maintain permalink structure and avoid a 404 error when loading external content?
wordpress
The feed for a site (http://www.affordabledrumlessons.com/feed/) shows fine in Google Chrome, but in Firefox and Safari it gives errors. I've tried clearing the cache, but that doesn't solve the issue. Any idea what could be causing the problem?
This isn't a WordPress issue. An RSS feed is an XML document created by your server for end users to consume updates or changes through an RSS reader. A web browser is not an RSS reader. Every browser will handle an RSS feed differently - and they'll do even stranger things if they don't recognize it as XML. Often, Chr...
Issue with RSS Feed in Firefox and Safari
wordpress
WordPress is installing a PHPSESSID cookie as soon as someone lands on my site. Under new EU law if its non-essential i have to block it so that a user can opt-in. But if it is essential its ok as long as I detail its use on my site. This is the problem. I look after about 20 WordPress sites and only 2 of them install ...
The cookie looks like it is being set by the PHP session handling process. WordPress 'out of the box' doesn't use sessions, which would seem to point towards either your theme or a plugin. If you search your code base for 'session_start' you may be able to track down where the session is being initiated. PHP can also b...
Worpdress PHPSESSID / EU law
wordpress
I'm running WordPress 3.3.2 with my own custom-built theme that has 4 custom post types. Currently, I'm looking for a way to replace the search link from <code> example.com/blog/?s=findme </code> with <code> example.com/search/findme </code> . I've seen that WordPress already has the possibility to generate search resu...
I still haven't found the reason why I was getting different results between the two searches, but I decided I want to go with the permalink search option and just adjust that to my needs. Here's the simplified snippet that helped me filter the search results: <code> function define_search_permissions() { global $wp_po...
Different results between permalink and query var search
wordpress
I'm fairly new to wordpress and am coming across new things each day - one was today when I happened across <code> get_terms </code> and noticed that it was basically the same as <code> get_category </code> . Any particular reason to use one or the other? Is there something that I'm missing?
As you dive into WordPress, you'll find that WordPress has a lot of wrapper functions. For instance, there's <code> add_theme_page </code> that's just a wrapper of <code> add_submenu_page </code> . That's certainly not the only example ( <code> add_submenu_page </code> itself has a bunch of wrappers, in fact). If you l...
get_terms vs. get_categories: does it matter?
wordpress
Live site. My blog page is showing only the very first published page, and not the subsequent posts. I've noticed, too, that when viewing the page source, the blog page seems to be using single.php instead of index.php which is what I've set the template to be. Could this be the issue? Below is the code in question: in...
It appears that <code> blog.php </code> is a custom static page template , yes? If so, then the primary loop will display the post content of the static page to which it is applied. If you want to create a custom page template that displays blog posts, you will need to create a secondary loop to query/output the requir...
blog page showing only first post
wordpress
How can I exclude visited posts from a loop? I have a loop of recent posts on a single post page that excludes the current post and I want to extend the amount of times users browse by filtering out the ones they've already seen. Here's the basic loop. <code> &lt;?php $featured_post_id = get_the_ID(); global $post; $ar...
This is a heavier question than you think. You'll need to do quite a bit: Set a cookie in the user's browser to keep track of the posts they've seen. Pull data out of that cookie to get a list of post IDs Add this to the array with the <code> $featured_post_id </code> to pass it in the <code> post__not_in </code> param...
How to exclude visited posts from loop
wordpress
Some examples in WordPress' docs pass a filename to <code> add_action </code> rather than an action name. For example, <code> add_action( 'load-post.php', 'callback' ); add_action( 'load-post-new.php', 'callback' ); </code> What are the valid filenames for the first argument in <code> add_action </code> ?
Just found my answer. Those aren't filenames but examples of the <code> load-(page) </code> action.
Valid filenames for add_action's first parameter
wordpress
I want to create a handful of pages that I do not want the client to have access to through the edit pages admin screen. I do want the pages to have all the normal functionality of pages in other parts of the control panel. For example, I want the pages to show on... Appearance > Menus ...so the client can reorder or r...
Indeed there is a way. <code> function wpa53074_admin_exclude_page( $query ) { if( !is_admin() ) return $query; global $pagenow; if( 'edit.php' == $pagenow &amp;&amp; 'page' == get_query_var( 'post_type' ) ) $query-&gt;set( 'post__not_in', array( 99 ) ); // &lt;- page ID to hide return $query; } add_action( 'pre_get_po...
Is there a way to remove or hide individual pages on the Edit Pages screen?
wordpress
I've been hacking all day at a custom post type search/filter system. So far I have this: <code> function kdev_property_query($query) { if(isset($_POST['rooms_n'])) $_SESSION['rooms_n'] = $_POST['rooms_n']; if(isset($_POST['univer'])) $_SESSION['univer'] = $_POST['univer']; if(isset($_POST['area_t'])) $_SESSION['area_t...
On your search form you use NULL (as a string) for Any selection. When the form is submitted it is sent as a string with the contents of the word null. Your isset then sees that, its set and sets the session to null (as a string). Which in turn messes up your query. To fix use: <code> &lt;option value=""&gt;Any&lt;/opt...
Custom post type search using $_SESSION and pre_get_posts
wordpress
I have been reading up on debugging. I watched Chip Bennett's video on wordpress.tv and was inspired to take debugging seriously. What I have found in my reading up though has confused me a bit. I know about <code> define( 'WP_DEBUG', true ); </code> and some of the debug plugins like 'debug bar' and 'firephp' and also...
You have several tools at your disposal when working with native WordPress debugging. PHP Debugging - <code> WP_DEBUG </code> is the native WordPress PHP constant for debugging WordPress errors. It sets PHP's error reporting to to <code> E_ALL </code> for warnings when deprecated functions are used and if none are foun...
Getting a WordPress Debug Strategy
wordpress
Shopify's Cycle lets you alternate between things within a loop. Here's my example: <code> &lt;div class="{% cycle 'first', 'second', 'third' %}"&gt; {% include 'product-grid-item' %} &lt;/div&gt; </code> My question, is there anything like this for Wordpress? I'd love to be able to cycle through some kind of setting -...
Short answer, no. But that is a pretty cool feature! To so something similar in WordPress, you'd need to code some kind of iterator in PHP and have it do the logic for you. For example: <code> $classes = array( 'first', 'second', 'third' ); $iteration = 0; if ( have_posts() ) : while ( have_posts() ) : the_post(); $ite...
Does Wordpress Loop have a function like Shopify's cycle?
wordpress