question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
I have a plugin that uses the <code> wp_editor() </code> function to load an instance of the TinyMCE editor. However, the editor is affected by custom styling to make it look similar to the theme through the <code> add_editor_style() </code> function. While this may be great in giving the user an idea of how the conten...
While @s_ha_dum’s solution works fine on a custom plugin page, it will fail if you use TinyMCE on a post editor page after the first editor instance has been called, because it would either affect all editors or at least the editors later on the same page. TinyMCE parses custom styles into its settings during the first...
Load visual editor without custom styling
wordpress
I'm trying to add a rewrite rule to Wordpress. I want to rewrite: "http://www.domain.com/plm_check/var_a/var_b/var_c/" to actually use a file from "http://www.domain.com/wp-content/plugins/plm/webservices/plm_check.php?var_a=...&amp;var_b=...&amp;var_c=..." I've registered it like this: <code> /* Register rewrites for ...
Here's a quick (hopefully error-free!) example of adding an internal rewrite and loading a plugin file to process those requests. This will give you access to the WordPress environment so you can use the database , etc.. The general steps are: add your rewrite and point it to index.php with your custom query vars appen...
External Rewrite Rules
wordpress
Maybe i'm wrong but it seems that this question has not been previously solved yet: There is some iframe inside post content and I want to get rid of that iframe when the rss feeds are generated. To generate rss feeds, I'm showing full post content. I started looking at <code> strip_tags() </code> but it does pretty mu...
One potential option is to use <code> preg_replace </code> to do a regex match on your content and replace the iframe with empty space. So this function: <code> function rss_noiframe($content) { $content = preg_replace( '/&lt;iframe(.*)\/iframe&gt;/is', '', $content ); return $content; } add_filter('the_excerpt_rss', '...
How to filter out an iframe from feed
wordpress
I have a mulisite setup and I am using one theme for multiple sites in it and each site have a custom layout and design. So for that I need to create a child-theme. But I don't know how to create multiple child theme for each site so I can add customization in each child theme style.css, footer.php, function.php, heade...
You can copy your <code> canvas-child </code> folder and call it <code> canvas-child-2 </code> , or similar. Then open up <code> style.css </code> in <code> canvas-child-2 </code> , and edit the <code> Theme Name: </code> . Do this for as many different child themes you need. You will then need to enable the child them...
WordPress Multisite Multiple child theme
wordpress
I have been reading in the codex about the read more issue. It says when using the_excerpt, the character limit is 55 and then the read more should display which should look like this [...] I am not seeing that in my excerpt. I have also tried several filters for testing. <code> function custom_excerpt_length( $length ...
I think <code> if( has_excerpt()) </code> return false that's way its return full content remove condition and only use <code> the_excerpt() </code> then it will work. I have another solution that i use :) <code> $content = get_the_content(); $short_content = implode(' ', array_slice(explode(' ', $content), 0, 10)); ec...
read more doesn't display
wordpress
is there any way to include custom post title as search term. I create custom post types - VHS, DVD, Blu Ray. Then in search box when I write DVD I want to list all posts from custom post type DVD. Thank you all in advance :)
If you register the post type with <code> public </code> set to <code> true </code> , the titles will be included automatically. You shouldn't have to do anything to make this happen. Something as simple as this from the Codex : <code> function codex_custom_init() { $args = array( 'public' =&gt; true, 'label' =&gt; 'Bo...
Custom Post Title as search term
wordpress
I'd like to add a "fast facts" section to a wordpress site - an area in the sidebar where snippets of text are rotated. Where is the best place to store things like this? Widgets don't really allow repeated items grouped in a good way &amp; i don't want to add a post type as that would be available as a page with a URL
It sounds like you do want a custom post type, you just want to set the <code> public </code> argument to <code> false </code> . The <code> register_post_type() </code> has lots of arguments that will let you do everything you probably want. Along with <code> public </code> , you'll probably set <code> has_archive </co...
Text snippets shared across posts
wordpress
I'm new in wordpress. I want to display all author list with its ID. I'm using <code> wp_list_authors </code> function but didn't get any author id from the author list. So, How can I get Author's ID in listing of all author?
You can use the following: <code> // prepare arguments $args = array( // search only for Authors role 'role' =&gt; 'Author', // order results by display_name 'orderby' =&gt; 'display_name' ); // Create the WP_User_Query object $wp_user_query = new WP_User_Query($args); // Get the results $authors = $wp_user_query-&gt;g...
Author's Id from wp list authors function
wordpress
I've been writing up a function to assign classes to default WordPress widgets that I choose. After a bunch of research and modifications, I came up with the function below. A quick explanation of what it does: The variable, <code> $classes </code> , holds the class name I want to assign each type of widget to and each...
The problem isn't how you are accessing the array, as you put it. It is with the <code> str_replace </code> line. That generates bad markup. You are replacing <code> class=" </code> with your classes, so <code> &lt;aside id="whatever" class="abc"&gt; </code> becomes <code> &lt;aside id="whatever" full-blocks"&gt; </cod...
Trouble accessing a multidimensional array to add classes to default WordPress widgets
wordpress
How can i get movies there are today in cinema, for example my code display the movies in time that shoud apear 16 January,17 January..., how can i display only the movies in this day. Ex: today is Wensday 16 January 2013, how can i get only the posts(movies) that shoud apear only today If i have 2 movies that premiere...
This will compare today's date to the date meta key and select posts with a dates that are greater than or equal : <code> 'meta_compare' =&gt; '&gt;=' </code> If you want to match only today's date, change it to just equal : <code> 'meta_compare' =&gt; '=' </code>
Getting post by specific date in Advance Custom Field
wordpress
I currently have 2 issues with Custom Post Types... First of all I'm trying to setup custom columns in Admin to display and act correctly. I have a Custom Post Type called 'acme_products' and a Taxonomy called 'product_type'. I have followed the Yoast tutorial http://yoast.com/custom-post-type-snippets/ (amongst others...
As of WP 3.5 , <code> register_taxonomy </code> accepts a <code> show_admin_column </code> parameter: "Whether to allow automatic creation of taxonomy columns on associated post-types".
Custom columns for multiple custom post types
wordpress
We have a bespoke Wordpress plugin, which adds a meta box to the edit post page. The plugin accesses data from a semi-private HTTP REST API. The connection is authenticated (DIGEST) and accessed regularly - every person writing a post will interact with it several times (usually in tight bursts) and there are > 100 suc...
It is not possible, at least not within reason, to solve either of these issues due to fundamental limitations of PHP in a web envionment (mod_php). Class variables do not persist between web requests, so the Keep-Alive part of the problem cannot be fixed because all the resources (i.e. curl handle, tcp socket) will be...
Re use authenticated HTTP connection or cUrl handle
wordpress
After having timthumb.php exploited. The site was upgraded to WP 3.5 It was compromised again, (wp-config included encrypted data as well as the functions.php in the wp-include directory. After reviewing various sites, I opted to remove ALL files (after backing up the site) and reinstall the code to insure no corrupted...
"Generally this happens when someone has mistakenly put index.php from a theme in the WP install folder, where it overwrites the index.php that is the main WordPress file. Download WordPress again, and take the one file, index.php from its root folder, replacing the file you now have as index.php It sometimes means som...
After being hacked Fatal error: Call to undefined function get_header() in 404.php on line 1
wordpress
We have an appointment calendar plugin at WordPress Plugin Repository. In our plugin <code> readme.txt </code> , we have already added tags like: <code> === Appointment Calendar === Contributors: a.ankit, FARAZFRANK, harimaliya Link: http://appointzilla.com/ Tags: appointment, booking, calendar, appointment scheduling ...
There was an attack yesterday on WP servers, make a small push and try again. First, run the readme validator and make sure yours matches as much as possible the official example .
Our plugin tags not appearing in WordPress Plugin Repository
wordpress
On one of our latest projects I'm planning to use the index.php file to display different taxonomy layouts. Basically I'm planning to use <code> is_tax( 'sometaxonomy' ) </code> to display the data/loop for different taxonomies. Are there any performance concerns I should address? Is it better to use taxonomy-$taxonomy...
TL;DR Template: Performance not so much, semantics however, use hierarchy! TL;DR Query String: Use provided hooks, never edit directly. The Template File Apart from performance, first look at semantics. If you direct your browser to a taxonomy archive, WordPress will look for the following files (straight from the Code...
Performance concerns: index.php vs taxonomy-$taxonomy.php
wordpress
I am trying to make a function and exclude in the post query that way im able to define the id's in my function but it is only excluding 1 post instead of the 4 it is returning. any suggestions on how I can go about successfully executing this? function in the functions.php file <code> function slider_exclude(){ $exclu...
Your PHP is wrong. <code> function slider_exclude(){ $exclude_query = query_posts(array('showposts' =&gt; 4, 'cat' =&gt; 'news',)); foreach($exclude_query as $post_ids){ return $post_ids-&gt;ID.','; } } </code> Looks like you are trying to build a comma delimited string but that isn't how <code> return </code> works. W...
exclude ids through post__not_in
wordpress
I need to integrate this plugin with my WordPress site, and the categories must be in this format: <code> "Option 1": {"Suboption":200}, "Option 2": {"Suboption 2": {"Subsub 1":201, "Subsub 2":202}, "Suboption 3": {"Subsub 3":203, "Subsub 4":204, "Subsub 5":205} } </code> How can I get that? I tried the options of the ...
Here is a fast example using <code> get_categories </code> instead of a plugin or the walker class, maybe it will help you in the right direction, it will list all children of a parent category in json format. As brasofilo mentions since you require a specific format you will want to build a custom array. <code> // let...
How to list categories and subcategories in JSON format?
wordpress
I am getting the error illegal string offset when creating a checkbox in the admin. my code look like this. <code> &lt;input type="checkbox" id="slideThre" name="custom_settings[checked]" value="1" &lt;?php checked(1, $custom_options['checked']);?&gt;/&gt; </code> There is no error when I check the box and save. The er...
Checkboxes only send data when checked. When unchecked, there is no post (or get) data. You need to check if set using isset() <code> if (isset($_POST['custom_settings']['checked'])) { /* it was ticked */ } </code>
wordpress illegal string offset 'parameter' error
wordpress
How do I use wp_enqueue_script so that I get protocol neutral URLs? Here is how I'm currently using it: <code> &lt;?php wp_enqueue_script('name', get_bloginfo('template_directory'). '/js/name.pack.js'); ?&gt; </code> I saw that <code> home_url() </code> is protocol aware so I figured <code> theme_url() </code> would be...
You can't -- URLs must have a protocol for WordPress to enqueue them. What you can do, though, is detect which protocol to use and then use that. <code> $protocol = is_ssl() ? 'https' : 'http'; $url = "$protocol://example.com/resource"; </code> But for enqueuing scripts from your theme, you should use get_template_dire...
Protocol neutral URLS with wp_enqueue_script (SSL issues)?
wordpress
I have some difficulies styling Meta Box content of a custom post. No CSS styling is applied. I made a really simple testbased on what I have read on the other post here. metabox creation: <code> add_meta_box('wpptabs_company_details', __('The Meta box name', 'wpptabs'), array(&amp;$this, 'render_meta_content'), 'wppta...
The metabox div gets an ID of 'meta_' + your metabox ID, thus: Sorry, that was me looking at my own metaboxes, forgetting that I actually prefix them like that to differentiate the container from elements within the container :( Let's work through your code and see if we can find the answer. First, your metabox has the...
CSS styling not working in a custom metabox
wordpress
I am adding a list of suggested plugins to my theme using TGM Plugin Activation - https://github.com/thomasgriffin/TGM-Plugin-Activation/ However, when I run theme check, about 40 or so recommendations popped up because the plugin uses variables in translatable functions. I was able to remove about half of the problems...
The translation strings not only get parsed during rendering (output on screen/in browser), but also by the GNU gettext parser. This one is not a PHP parser, so it can't fetch variables. This is the only part of a Theme or a Plugin, where you need to repeat yourself and add the plain string to every translation/gettext...
variables in translatable text
wordpress
This is the current output for my WP_LINK_PAGES, notice the unnecessary <code> &lt;/p&gt; </code> tag at the end. My code for my custom WP_LINK_PAGES can be found here. <code> &lt;div id="link_wrap"&gt; &lt;span class="classlinks"&gt;1&lt;/span&gt; &lt;a href="http://themeforward.com/demo2/?p=1948&amp;#038;page=2"&gt;&...
the <code> &lt;/p&gt; </code> is just a browser artefact to compensate for a missing <code> &lt;/span&gt; </code> ; your code is missing <code> . $args['link_after'] </code> in two locations; the corrected code: <code> // WP_LINK_PAGES: Add prev and next links to a numbered link list add_filter('wp_link_pages_args', 'w...
WP_LINK_PAGES Generating Unnecessary Tag
wordpress
In my code below I need to close the div "link_wrap" which I created with <code> $args['before'] = '&lt;div id="link_wrap"&gt;'; </code> When I try to paste <code> $args['after'] = '&lt;/div&gt;'; </code> above <code> return $args; </code> it adds the appropriate closing div but also renders the rest of my code, which ...
First, declare the after arg at the beginning of your code: <code> $args['before'] = '&lt;div id="link_wrap"&gt;'; $args['after'] = '&lt;/div&gt;'; </code> When there is a next page, the arg is overwritten, so you'll have to add the closing tag at the end: <code> if ($page&lt;$numpages) # there is a next page $args['af...
Closing WP_LINK_PAGES DIV ID w/After Argmuent
wordpress
When Im in wp-admin and editing a page and whant to make underline, bold and italic it dont appear on the site. I understand therese something i have to define in the css or thru wp-admin ? NOTE: I want the user to easly edit and i know how to do it thru css. But what I want is to edit thru the edit-page.
If it is editor mode specific, then make a CSS file named: <code> editor-style.css </code> and then add the following code into <code> functions.php </code> within PHP tags: // CUSTOM EDITOR STYLES // This theme styles the visual editor with editor-style.css to match the theme style. add_editor_style(); Now put some CS...
How to align bold,italic and underline in wp-admin?
wordpress
I made some changes in comment-template.php , wp-comment-post.php so now I am storing the comments withot attaching with any post or page (I am setting the comment_post_id to 0). But now the problem is When I go on admin panel and see all comments the comments with 0 comment_post_id are not having option of spam , tras...
I found a way to hijack the comment before it's attached to its post in the DB. Using the snippet below you can attach every comment to your dummy post. Just change <code> COMMENT_ID </code> to the ID of your dummy post. No hacking of core needed! <code> &lt;?php add_filter('preprocess_comment', 'akt_hijack_comment'); ...
approve,spam,trash etc. options are not coming on comments in admin panel
wordpress
Is there any way to filter the categories of a post? I am using <code> wp_get_post_categories( $post -&gt; ID ); </code> i want to filter this listing i.e. <code> if(post_name or post_id == "some id or some name") {it should not be displayed} </code>
have you tried something like, <code> $post_categories = wp_get_post_categories( $post -&gt; ID ); foreach($post_categories as $c){ $cat = get_category( $c ); if ( $cat-&gt;slug != "cat" ) { echo "$cat-&gt;name"; }; } </code>
How to filter categories of a post
wordpress
Something like this, no excerpts or anything else. I couldn't find any plugin that can do it:
You could use wp_get_recent_posts() to get the latest posts, like: <code> &lt;h2&gt;Recent Posts&lt;/h2&gt; &lt;ul&gt; &lt;?php $args = array( 'numberposts' =&gt; '5' ); $recent_posts = wp_get_recent_posts( $args ); foreach( $recent_posts as $recent ){ echo '&lt;li&gt;&lt;a href="' . get_permalink($recent["ID"]) . '" t...
Need to setup grid like thumbnail of recent posts on sidebar
wordpress
Is there a simple way to temporarily stop a user role logging in with wordpress? For example, if I have a user role called media , how can I block them from logging in? I would like a custom message to appear on the website, for example like 'Site undergoing maintenance' So it looks like this... http://i.imgur.com/nDf7...
With a some digging and learning, I managed to combine various help and create these 2 functions... <code> // MAINTAINANCE MODE function site_maintenance() { if ( current_user_can('media') || current_user_can('genpo') ) { $logout_url = wp_login_url().'?mode=maintainance'; wp_logout(); wp_redirect( $logout_url, 302 ); }...
Temporarily disable user role login and replace with message
wordpress
I was using the Pinboard theme, but want to make modifications to it. Instead of editing the theme files directly, I wanted to try to make my changes using a child theme. Following the codex , I created a new folder named pinboard-child under /wp-content/themes/ . I created a style.css file, added the code below, and t...
"Template" should reference the parent theme: <code> Template: Pinboard </code>
Activating child theme returns "active theme is broken"
wordpress
I am using Contact Form 7 along with the add-on Contact Form 7 Dynamic Text Extension to pre-populate usernames and emails. I know this may be sort of a strange request but I want to be able to limit the number of submissions to one for each user only for one of my forms. Basically, it's a submission form for a contest...
Contact Form 7 does not save form submissions to a database, so you have no saved previous form submissions to check a current submission against. That means you'll need to have a plugin that can save entries to a database (the plugin author seems to recommend "Flamingo" for that). Once you've got those, you'll need to...
Limit one submission from each user using Contact Form 7?
wordpress
I have successfully pulled a custom post type through into a drop-down that is in a custom meta box. However, when displaying it on the front end I would like to also provide a link to the actual post, not just the name of the post. So I am guessing I need to save this as an array? Is this possible through a drop-down?...
Quite simple. Instead of saving the post title, save the post ID, so in the front end you can extract all necessary info. Like so: <code> get_post( $the_saved_ID_value ); </code> or <code> get_permalink( $the_saved_ID_value ); </code> . In you code, change this line: <code> echo '&lt;option value="'.get_the_ID().'" '.$...
Save an array from drop-down in custom meta box
wordpress
I'm building a <code> &lt;select&gt; </code> dropdown to display a list of terms for a custom hierarchical taxonomy. How do I know the depth of each term? I'd like to add some indentation for child-terms (the more deeply they're nested, the more indentation there should be). However I'm not able to retrieve the depth l...
You can use wp_dropdown_categories() : Display or retrieve the HTML dropdown list of categories. <code> $args = array( 'show_count' =&gt; 1, 'hierarchical' =&gt; 1, 'taxonomy' =&gt; 'my_taxonomy', ); wp_dropdown_categories( $args ); </code>
How to determine the depth of a term in a custom taxonomy?
wordpress
I am using the Mingle plugin to add some networking functionality for a website I am creating for a client. I am having Mingle handle displaying user profiles and friends, but WordPress to actually register users and put in fields. Mingle has the ability to add custom fields (ex: Twitter, Facebook, etc). However, there...
You're outside the loop, so you should supply a user ID: <code> get_the_author_meta( 'twitter', $user-&gt;id ) </code>
Displaying custom profile fields using Mingle Plugin
wordpress
I'm using the code below to display an image if the swap_select custom field value is true. If it's no it displays nothing. However when posts are first created no custom field exists. So what would the conditional be to account for no custom field at all and in that case display noithing? <code> &lt;?php $swap_value =...
I prefer <code> empty </code> for this because it considers a lot of things to be "empty" besides just an empty string, and that is the behavior I usually want. Be aware of that though. I am not 100% sure what you are doing but... <code> if( empty($swap_value) ) { // runs if no $swap_value, or an empty value } // OR if...
Help with this custom field conditional if no field is set display nothing
wordpress
I am developing one of my first plugins, and have come across a error: You do not have sufficient permissions to access this page The plugin has a wizard that uses several forms, obviously I don't want people selecting later forms using the menu. Is there a way to "silently" register a page? Basically, register the pag...
The mighty Codex holds the answers: If you're running into the »You do not have sufficient permissions to access this page.« message in a <code> wp_die() </code> screen, then you've hooked too early. The hook you should use is <code> admin_menu </code> . <code> $parent_slug </code> : Use <code> NULL </code> or set to <...
Silently register plugin pages
wordpress
I've just installed latest version of Slick Social Share Buttons on top of Responsive theme. In the settings page in Twitter Username I provided my twitter username. The number of the times the link was hared shows fine in the widget, but if I click on the link, I'm taken to URL <code> https://twitter.com/search/realti...
This should work just fine, because the functionality to share a website on Twitter should include the URL that you want your users to share. Keep in mind that the realtime Twitter-Searchfunction just shows recent results, not all of them, so the Link will never list all Tweets about your site. The additional informati...
Slick Social Share Buttons plug-ins with Responsive theme - number of tweets link problem
wordpress
I've created a custom post type with front-end submission. I added a delete link using <code> get_delete_post_link </code> ... which works great, except it brings me to a "Page not found" after the post is deleted. I'd like to be able to redirect to another page after the post is deleted. I know I can use the <code> ad...
I would create an AJAX Call from the delete post Link. First, register the AJAX function: <code> add_action( 'wp_ajax_wpse_delete_post', 'wpse_delete_post' ); </code> I would not add the AJAX function to the nopriv Users, but if you want every visitor of the site (ignoring capabilities) to be able to delete a post, you...
Redirect after get_delete_post_link
wordpress
Currently, in my plugin Contextual Related Posts, I have an option to automatically add the related posts to the content using <code> add_filter('the_content,'ald_crp') </code> I know I can change the priority of the filter by adding a number greater than 10 (which is WordPress default). <code> add_filter('the_content,...
Save the priority in your options and pass that value to your <code> add_filter </code> : <code> add_action( 'template_redirect', 'wpse_81687_prepare_filter' ); function wpse_81687_prepare_filter() { $my_options = get_option( 'my_options' ); $priority = isset ( $my_options['content_filter_priority'] ) ? $my_options['co...
Custom priority with the_content filter based on user input
wordpress
Suppose I'm using a Theme which has a custom panel in the admin area, or I'm using a Plugin, has similar Admin menu button. But all such button are only visible to Administrator. When I'm loggin in from an editor account they are gone. But I need them badly. I want an Editor can have access to those panels, and I want ...
functions like add_submenu_page() ask for a capability when they are called, as in de code below: <code> add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function ); </code> <code> $capability </code> contains the capability required for this menu to be displayed to the user. When you...
When using a user role editor how to find out any plugins' or themes' role?
wordpress
I currently have these custom permalink rules: /%category%/%postname%/ I'd like /%category%/%postname%/%sometext% to display the same as /%category%/%postname%/ - from there, I will either use PHP or jQuery to display different content on the page. EG: /about-us/team/mike to display the /about-us/team page, and then I'...
You will need to whitelist a new query_var: <code> function add_query_vars($aVars) { $aVars[] = "subpage"; // represents the name of the product category as shown in the URL return $aVars; } // hook add_query_vars function into query_vars add_filter('query_vars', 'add_query_vars'); </code> You will need then need a rew...
Routing 'fake' sub sub posts
wordpress
I need to get all sub-posts of a specific (root) parent id. <code> get_posts( array( 'numberposts' =&gt; -1, 'post_status' =&gt; 'publish', 'post_type' =&gt; 'microsite', 'post_parent' =&gt; $root_parent_id, 'suppress_filters' =&gt; false ) ); </code> WP-Codex: get_post() function has the post_parent but no child_of pa...
You will need to loop over those posts and then do more queries for each post, repeating until you find no posts in a query. e.g. <code> function get_posts_children($parent_id){ $children = array(); // grab the posts children $posts = get_posts( array( 'numberposts' =&gt; -1, 'post_status' =&gt; 'publish', 'post_type' ...
How to get all children and grandchildren of a hierarchical custom post type?
wordpress
I'm trying to make a product page template, editable by client, which will have 3 different NextGen Galleries per page. In the product page admin area, I want the client to be able to select which 3 NextGen galleries to display, and in which order. What do I put in my template page, and (I'm assuming) functions.php? He...
You can add galleries directly to a template by calling do_shortcode() to run the gallery shortcode. <code> &lt;?php echo do_shortcode('[nggallery id="1" template="example"]'); ?&gt; </code> Edit: sorry, writing decaffeinated so short attention span :) Add some custom fields to your product pages to let your client pic...
How to make page template with admin able to select NextGen Galleries to be part of the layout?
wordpress
I'm using WP as a CMS, not a blog. I have a lot of pages (not posts) that need to have different content per page in the sidebar. The content (html, images, php) in the sidebar will be different depending on what page you are viewing. Since I have a lot of pages, I don't think checking for what page is currently displa...
Add a metabox to your post type, see stackexchange-url ("this answer") for details. In you sidebar look for the post meta key <code> _t5_extra_box </code> and display its content if it is available. But … I would do this in a plugin and move the rendering into a widget. This is about content mostly, so it doesn’t reall...
How can I add multiple content-editable blocks without a plug-in?
wordpress
Is it possible to change the image size of the thumbnails in the new media uploader? For example images are currently displayed using the "thumbnail" image crop size and I would like them to be the "medium" image crop size.
Supposing that I'm interpreting your Question correctly ... The thumbnails displayed in the new Media Uploader are already the <code> medium </code> sized ones, being constrained on the fly. So, it's a matter of applying some CSS styling to increase their size. Maybe other style adjustments are necessary, this is just ...
How to change the image size in new Media Uploader (ie use medium vs thumbnail)
wordpress
I am looking at the feasibility of converting a client's site from countless hand-built web pages to a WordPress installation. The challenge is that we have a free area and a members-only area. The members-only area is a folder protected by standard Apache .htaccess / htpasswd authentication. The password folder is ext...
Does a double install sound feasible and the right approach? Given your restrictions, yes...I can't think of any other way to do it with a single install. If there was a way to get the legacy software to control member accounts via any other system (perhaps dumping to a CSV which can then be read into a MySQL table via...
Members area with externally-managed htaccess / htpasswd authentication?
wordpress
I think the title pretty much says it all! I'm working my way through various tutorials on how to add an options page to my test plugin and am struggling to understand the <code> Register_Settings </code> function. Every tutorial I have found quotes the codex for the arguments then uses the same text in the <code> Opti...
The codex defines the function as: <code> register_setting( $option_group, $option_name, $option_validate_function ); </code> <code> $option_group </code> is settings group name. Use when displaying on a settings page for example <code> $option_name </code> is the database entry name <code> $option_validate_function </...
Difference between Option_Group and Option_Name in Register_Settings
wordpress
I've seen a lot of posts out there in the Webiverse about assigning a page as a parent of a custom post type. After four hours I can't find a solution and need some help. I've create an "About" page that is the parent of an "Our People" page. I've also create a custom post type called "People". And I've created a custo...
This should work: <code> 'rewrite' =&gt; array( 'slug' =&gt; 'about-us/our-people'), </code> combined with: <code> 'has_archive' =&gt; false, </code> Make sure to visit the Permalinks settings page in your admin after you made the changes to flush the rewrite rules.
Can a custom post type have a Parent Page?
wordpress
One of my sites consistently fails to publish scheduled posts. I've tried disabling plugins, using Twenty Twelve, etc. with no luck. I installed the Core Control plugin and noticed that there is no function associated with the publish_future_post hook. On my other sites, there is a hooked function check_and_publish_fut...
You can also disable the auto wp-cron from loading and setup a manual cron job on your server. Add the following line to your Wp-config.php <code> define('DISABLE_WP_CRON', true); </code> and then on your server/control panel create a cron job to run the following: <code> wget http://www.yourdomain.com/wp-cron.php &gt;...
How to fix missing function in wp-cron?
wordpress
I'm curious to know what is the so called "main query"? What I have is two queries on front page. <code> if (have_posts()) : while (have_posts()) : the_post(); // do the main loop endwhile; endif; $posts = new WP_Query(array('post_type' =&gt; 'some_other_post_type')); while ($posts-&gt;have_posts()) : $posts-&gt;the_po...
Your filter has a bug in it, namely when you call is_main_query, you're not checking if the passed query is the main query, your checking if the currently active query is the main query, which will always be true. So instead try this: <code> add_action( 'pre_get_posts', 'some_name'); function some_name($query) { if ($q...
What is "main query"?
wordpress
Instead of calling a script from a file, I put a number of my javascripts in a template file called codes.php. I then call codes.php in the footer by pasting <code> &lt;?php include (TEMPLATEPATH . '/codes.php'); ?&gt; </code> into footer.php Should I continue with this method, or should I be saving each script in its ...
If I interpret the question correctly you: Don't have any .js javascript files Output any javascript you have from an .php file (presumably code) Include this javascript on the bottom of the page by including the .php file. So you are actually doing: Correct Combining all the javascript in one file Having the javascrip...
Proper Javascript Implementation
wordpress
I'm using this to allow me to display my comments for posts on category pages: <code> &lt;?php $wp_query-&gt;is_single = true; comments_template(); $wp_query-&gt;is_single = false; ?&gt; </code> However I don't want to display the comment form. Is there a way to display the comments only on a comment page?
Use <code> get_comments() </code> and pass the post ID as parameter. Then print the result as regular list. From a plugin I have published recently: <code> function t5_list_comments( $atts, $content = '' ) { '' !== $content &amp;&amp; $content = wpautop( do_shortcode( $content ) ); if ( ! isset ( $atts['post_id'] ) ) r...
Display comments on a comment page without form
wordpress
My Code getting authors written post categories but just 2 ID has author lists category.. I replace <code> $current_user-&gt;ID </code> but it is not worked. <code> &lt;?php $categories = $wpdb-&gt;get_results(" SELECT DISTINCT(terms.term_id) as ID, terms.name, terms.slug FROM $wpdb-&gt;posts as posts LEFT JOIN $wpdb-&...
try something like this... you need to first call <code> global $post; </code> then get the author id like <code> $author_id = $post-&gt;post_author; </code>
How can i list current author's categories?
wordpress
I've been asked to build a WordPress that limits access to posts with a particular custom post type based on the logged in users level. There will be a number of pre made user roles and they would like to choose which levels can view each post when the post is written. What is the best way to do this?
There are two ways to do this. Almost any decent membership management plugin will enable you to restrict content to a given user role and plugins such as Role Scoper are even more flexible. For a more code-based solution you would add some variation of the following to the desired theme template files where ever neede...
Limit access to page depending on user level
wordpress
A site has thousands of images in the uploads folder. ISP has threatened to shut it down because it is about to exceed server limits for the max number of files in one directory. I looked at the Settings > Media panel and there is the unchecked option "Organize my uploads into month- and year-based folders" If I check ...
If I check this, what will happen to the existing images in the uploads directory (will they be re-organized?) No. The old structure is preserved and new files are added to the chosen new structure If not, can someone recommend a way/plugin to refile them in the new structure? I'd like to tidy up. The problem you will ...
what happens to existing media files when I switch to year/month directory structure format?
wordpress
I'm working with a Lucidpress theme at the moment. A client has asked that the "Lucidpress Options" title of a metabox on the page editor screen be changed. I have searched through the Lucidpress theme and have not found anywhere to change the title. Does anyone know, offhand, where to find this? Can anyone at least te...
Look for <code> add_meta_box </code> or <code> grep </code> the Lucidbox directory for the metabox title-- "Lucidpress Options". It shouldn't be too hard to find. As I don't use that theme, or any other publicly released theme, I don't know what else to say to you.
Change the title of an Administration Panel
wordpress
I'm trying to practice with setting up a front-end post submission form. And I'm getting this error: <code> Warning: Cannot modify header information - headers already sent by (output started at /home/sadlight/public_html/members/wp-content/themes/default-child/announcement-submit.php:1) in /home/sadlight/public_html/m...
As Otto pointed out, you're sending data to the browser before calling <code> wp_redirect() </code> . <code> get_header() </code> will output the page's HTML <code> &lt;head&gt; </code> You're printing the entire form to the page before processing it. To fix the "headers already sent" issue, you need to move all of you...
wp_redirect "headers already sent" after front-end submission form
wordpress
Another user on here suggested that my use of queries was incorrect so I'm changing the code. However, the pagination in the first block of code (below) isn't showing up in the HTML while the second one (my original) shows up fine. This one doesn't work (new code): <code> $paged = (get_query_var('paged')) ? get_query_v...
Rather than attempt to fix your query, I recommend you sidestep it entirely by using custom post type archives! With permalinks on, you should be able to view a list of all your movies posts by going to: <code> example.com/movies </code> Then, in your theme, create <code> archive-movies.php </code> , and it will be use...
pagination doesn't show up for custom post type
wordpress
I tried to add a custom page to my Wordpress template. That part is good. What I´m stuck with is a common sidebar that appears although I registered a custom sidebar for it. I am calling the sidebar... <code> &lt;?php get_sidebar('dfth'); ?&gt; </code> And registering sidebar (below there is default sidebars registered...
<code> get_sidebar('dfth') </code> looks for a <code> sidebar-dfth.php </code> file in your template directory. If not found, it loads the default sidebar. To call the sidebar you registered in a template, use e.g. <code> &lt;?php if ( is_active_sidebar( 'dfth' ) ) : ?&gt; &lt;div class="first dfth-widgets"&gt; &lt;?ph...
Stuck with sidebar registering
wordpress
I can't get meta_queries working correctly on get_users(). For the life of me can't figure out what I'm doing wrong. <code> $args = array( 'meta_query' =&gt; array( 'relation' =&gt; 'AND', array( 'key' =&gt; 'minbeds', 'value' =&gt; $rooms, 'compare' =&gt; "&lt;=", 'type' =&gt; 'numeric' ), array( 'key' =&gt; 'maxbeds'...
<code> meta_query </code> parameter is an array of arrays, <code> $args = array( 'meta_query'=&gt; array( array( 'relation' =&gt; 'AND', array( 'key' =&gt; 'minbeds', 'value' =&gt; $rooms, 'compare' =&gt; "&lt;=", 'type' =&gt; 'numeric' ), array( 'key' =&gt; 'maxbeds', 'value' =&gt; $rooms, 'compare' =&gt; "&gt;=", 'ty...
get_users meta_query
wordpress
I have a custom-post-type named <code> my_projects </code> and a custom-taxonomy called <code> project_tags </code> . I want to write a function that is returning 5 posts of this post-type based on a given taxonomy term. So I want to call <code> &lt;?php get_related_projects("Car"); ?&gt; </code> and get 5 posts that a...
Change your <code> $args </code> array a little bit: <code> $args = array( 'post_type' =&gt; array( 'my_projects' ), // it need to get the posts from this post_type 'order' =&gt; 'DESC', 'posts_per_page' =&gt; 5, 'project_tags' =&gt; $term // search taxonomy ); </code> Other ways to search for taxonomy terms can be fou...
Loop for custom-post-type comparing taxonomy terms for "related" posts?
wordpress
What I'm Trying To Do I have set up a custom post type for 'movies' and below is how I set up the template. Basically, I am trying to get <code> a.thickbox </code> (in the code below) to open a modal window with more info on the movie. Notice the addition of <code> &amp;pid=&lt;?php echo $post-&gt;ID; ?&gt; </code> at ...
It would appear your use of Thickbox is the culprit. When opening a thickbox via the anchor, the thickbox parameters must always be last, else the other parameters will be removed, e.g. your movies Post ID http://devll.wordpress.com/2009/10/01/jquery-iframe-thickbox-removes-parameter/ Firstly, your use of queries is in...
Get post info inside modal window?
wordpress
I have accidentally deleted a WP user. By deleting it, WP removed all the media files, pages etc. I could retrieve pages and posts from trash. But I could not restore media items. Is there a way to restore all items from trash back?
When deleting a user, WordPress displays a warning that unless you attribute the user's posts to a new user, it's posts will be deleted and you cannot undo those deletions. That means the only way to restore the posts and media is to restore a backup of the WordPress instance or database which you hopefully have.
How to restore all items from trash
wordpress
I want to output an image caption in this kind of format: <code> &lt;img class="alignleft size-medium wp-image-316" alt="Image Title" data-caption="Here lies the image caption" src="http://example.com/wp-content/uploads/image-400x266.jpg" width="400" height="266"&gt; </code> I got the basic caption code from WP Core an...
Basically the <code> img_caption_shortcode </code> filter allows you to completely replace the default image caption. If you want to do that, you'll need to ask WP to pass all the argument of the filter to your callback function. <code> &lt;?php add_filter('img_caption_shortcode', 'wpse81532_caption', 10, 3 /* three ar...
Can I the caption shortcode to set caption to a data attribute, and with the image's alignment intact?
wordpress
I can successfully query post results using query posts like so... <code> &lt;?php // The Query query_posts("gdsr_sort=rating"); // The Loop while ( have_posts() ) : the_post(); ?&gt; &lt;?php get_template_part( 'content', get_post_format() ); ?&gt; &lt;?php endwhile; // Reset Query wp_reset_query(); ?&gt; </code> I wa...
Here's a simple example of a PHP dropdown, hope this helps. <code> &lt;select name="mydropdownlist"&gt; &lt;?php $options = array('option1' =&gt; 'option 1' 'option2' =&gt; 'option 2' 'option3' =&gt; 'option 3'); foreach($options as $value =&gt; $caption) { echo "&lt;option value=\"$value\"&gt;$caption&lt;/option&gt;";...
Dropdown Menu for Query_Posts
wordpress
I am using the below to fetch the content of a page by its name and output the html <code> $my_wp_query = new WP_Query(); $page = $my_wp_query-&gt;query( array( 'post_type' =&gt; 'page', 'name' =&gt; 'some-page-slug' ) ); $page = $page[0]; $page_data['content'] = apply_filters('the_content', $page-&gt;post_content); </...
I may be misinterpreting you, but I think what you want to do is run through <code> strip_shortcodes </code> <code> $page_data['content'] = strip_shortcodes($page-&gt;post_content); $page_data['content'] = apply_filters('the_content', $page_data['content']); </code> Alternately you could conditionally hook that functio...
How to display the content HTML of a page without displaying the gallery code as well
wordpress
I have a widget with 6 different options. When I use <code> get_option </code> , it gives me a multidimensional array, with all my options inside the inner array, like so: <code> $options = get_option('widget_widgetname'); var_dump($options); </code> And the output for <code> var_dump </code> is: <code> array(2) { [2]=...
Widgets can be used multiple times. Your options will be passed to the widget directly and automatically, as part of the $instance variable. You should not be getting the options directly using get_option. The widget() function declaration in a WP_Widget derived class looks like this: <code> function widget( $args, $in...
Why does Wordpress stores widget options in a multidimensional array?
wordpress
I am using the default WordPress Gallery (along with the Cleaner Gallery plugin) to display some images. The one thing that the gallery doesn't seem to have is pagination. What I'd like to do is after 6 images add Previous and Next links to navigate through the pages. Having said that, there are several plugins that cl...
I decided to use the NextGEN Gallery instead of the default gallery, there is a few extra steps, but it's not too bad. Thanks, Josh
Paginate Gallery
wordpress
Bare with me as I explain this. I'm adding an Assistant Editor feature to my multiple author platform. In the box that appears in post-edit page, the Editors can tick which task that they have done (for instance proofread the article) and then check their username (so that they will be credited on the front post page)....
Use the same technique as $checked: <code> $disabled = ( $ed-&gt;ID != get_current_user_id() ) ? ' disabled="disabled"' : ''; </code> your code: <code> foreach ($alleds as $ed) { $checked = (in_array($ed-&gt;ID,(array)$currenteds)) ? ' checked="checked"' : ''; $disabled = ( $ed-&gt;ID != get_current_user_id() ) ? ' dis...
Limit checklist by the current user
wordpress
I own a self-hosted Wordpress 3.5 blog. I'm working on its security and I'm trying to prevent non-writers from accessing anything admin-ish they shouldn't. Recently I tried Better Wordpress Security , I really liked some of the htaccess suggestions they have. Primarily the one hiding /wp-admin/ with a unique key, even ...
I figured I'd just look in the Android application's source code to see how it communicates. You can quickly see XML-RPC in the source. So another way to access the blog is using Wordpress XML-RPC support. It was improved and enabled by default in version 3.5 very recently. I don't understand why they brought it back w...
Wordpress Security - How to block alternative Wordpress access
wordpress
Is it possible to make custom fields at the top, when writing a new post in admin panel ? Thank you.
<code> function wpse81499_move_postcustom_to_top() { if( 'post' != get_current_screen()-&gt;id ) return; ?&gt; &lt;script&gt; jQuery(document).ready(function(){ jQuery('#postcustom').prependTo('#titlediv'); }); &lt;/script&gt; &lt;?php } add_action( 'admin_footer', 'wpse81499_move_postcustom_to_top' ); </code>
Change places custom fields with title field in post wp-admin
wordpress
well, i'm confused. I can't seem to find out why my "Links" Menu doesn't show up in my wordpress admin. I have this in my <code> functions.php </code> file … <code> add_action( 'admin_menu', 'remove_links_menu' ); function remove_links_menu() { remove_menu_page('themes.php'); // Appearance remove_menu_page('tools.php')...
From the codex : "As of Version 3.5 , the Links Manger and blogroll are hidden for new installs and any existing WordPress installs that do not have any links. If you are upgrading from a previous version of WordPress with any active links, the Links Manager will continue to function as normal. If you would like to res...
Blogroll/Lins Menu not visible in my backend?
wordpress
I have a menu setup at the moment for a site I'm building that I'd like to change a little the way it pops up and doesn't popup :P At the moment, I hover over my main menu items if there are sub pages then a sub-menu pops up (standard wordpress I believe) I have other sub menues within this hierarchy that I'd like to l...
Yes, you can easily control just using css. Complete guide about wp nav menu on wordpress codex . And my fast solution for this: functions.php <code> add_theme_support('menus'); // Menus Support register_nav_menus(array('main_menu' =&gt;'Main Menu')); // Main Menu of Website </code> header.php <code> &lt;nav id="menu"&...
Controlling sub-menu within sub-menu
wordpress
I know this may be a bit crazy, and hopefully there's a way of doing this with out chopping up the core. I am trying to clean up my Wordpress admin menu's and in doing such I'd like to move Comments under Posts. The problem is obouvisly edit-comments.php is a main menu item and not a sub-menu item. I know you can make ...
Well one way to do it would be to add a new sub menu page and just remove the old one. <code> function wpse_80457_menu() { add_submenu_page( 'edit.php', 'Comments', 'Comments', 'manage_options', 'edit-comments.php'); remove_menu_page( 'edit-comments.php' ); } add_action('_admin_menu', 'wpse_80457_menu'); </code>
Making Comments, a sub_menu in admin menu
wordpress
I just did an action on the query using <code> pre_get_posts </code> and it didn't work. When I removed the <code> $query-&gt;is_main_query() </code> it did work. So, how do you know that what is the main query. I know there is the function <code> is_main_query </code> . What I am asking is there a way to tell which on...
<code> WP_Query-&gt;is_main_query() </code> method source (which function of same name calls) is very short and simple: <code> function is_main_query() { global $wp_the_query; return $wp_the_query === $this; } </code> The main query is the query that is stored in <code> $wp_the_query </code> global. But what is that gl...
How to know which one is the main query?
wordpress
I've recently discovered that we can insert a dropdown list of categories like this: <code> &lt;?php define( 'WP_USE_THEMES', false ); require( './wp-load.php' ); ?&gt; &lt;?php wp_dropdown_categories(array( 'child_of' =&gt; 0, 'class' =&gt; 'postform', 'depth' =&gt; 0, 'echo' =&gt; 1, 'exclude' =&gt; '', 'hide_empty' ...
Here is the answer: <code> $select_cats = wp_dropdown_categories( array( 'echo' =&gt; 0 ) ); $select_cats = str_replace( "name='cat' id=", "name='cat[]' multiple='multiple' id=", $select_cats ); echo $select_cats; </code>
How to use wp_category_checklist()?
wordpress
I am looking for something very simple but I'm not quite sure how to achieve this. I have been researching for the past 2-3 hours and gathered a lot of useful information. However, my knowledge in both PHP and WordPress isn't enough to do this from scratch. What I need is the following: When the user is not logged in, ...
You're going to want to use the <code> is_user_logged_in() </code> conditional tag to handle this. <code> global $current_user; get_currentuserinfo(); if ( is_user_logged_in() ) { echo "&lt;span&gt;Welcome $current_user-&gt;user_login&lt;/span&gt;". "&lt;a href='".wp_logout_url()."'&gt;Logout&lt;/a&gt;"; } else { echo ...
Wordpress login form script
wordpress
I need to have Featured Text displayed on my category page, as well as a Featured Image. The Featured Text can not be in the Post at all (just as a Featured Image is not in the Post). Does anybody know of a plugin that already does this? I've looked around a fair bit and can't seem to find anything. Many thanks.
I use the excerpt for this, as this is exactly what custom excerpt is for. The (custom/manual) excerpt could have been named "featured text", because that is also what it is. This excerpt is not to be confused with an automatic excerpt production. This excerpt will be drawn form the x first word of the content, when th...
Is there any way to have Featured Text, as opposed to Featured Image?
wordpress
After creating a custom post type I made a custom template file for the post ( <code> single-customposttypename.php </code> ). So the URL structure would be: <code> example.com/page/postname </code> , and <code> postname </code> would be the post that renders <code> single-custompostype.php </code> (this works fine). B...
There are two different ways to implement what you want to do, and both are perfectly valid, depending on your needs: Post-type archive index page Custom page template Post-type archive index page This implementation uses the WordPress template hierarchy to output the archive index page for your custom post type. For c...
How to Create Template File for Parent Page of Custom Post Type
wordpress
I want to be able to echo the URL of the featured image of a post and after looking some on the web I found the following which works fine when I put it in a loop in my front page template. <code> &lt;?php $thumbSmall = wp_get_attachment_image_src( get_post_thumbnail_id($post-&gt;ID), 'small' ); $urlSmall = $thumbSmall...
You can turn your snippet into a function that returns the post thumbnail URL of a post: <code> function wpse81577_get_small_thumb_url( $post_id ) { $thumbSmall = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'small' ); return $thumbSmall['0']; } </code> Usage, supplying the ID of a post: <code> &lt;?...
How to set global variable in functions.php
wordpress
I have a pair of Portfolio Slideshows inside of jQuery UI Tabs. One per tab with each pulling in a different page's gallery. When I switch between tabs the slideshows behave oddly. The main image is shrinking down to about 10% of its width, but keeping its height. When the page first loads, it seems to be working corre...
Not sure what is causing the problem, you could try adding this to init.js (inside the click function, before fade in): <code> $("#portfolio-slideshow0").css("width","882px"); </code>
Portfolio Slideshow Sliders Behaving Oddly When in jQuery Ui Tabs
wordpress
I've been reviewing a lot of information about WP theme and plugin security and understand the concept that you should escape attributes and HTML values in themes and plugins. I've seen <code> bloginfo() </code> and <code> echo get_bloginfo() </code> used both standard and inside an <code> esc_html() </code> or <code> ...
We have to look a bit deeper here to get an answer to your question. So, <code> bloginfo </code> is a simple wrapper around <code> get_bloginfo </code> . <code> &lt;?php function bloginfo( $show='' ) { echo get_bloginfo( $show, 'display' ); } </code> Notice the second argument <code> display </code> . Let's see what th...
From a security standpoint, should bloginfo() or get_bloginfo() be escaped?
wordpress
My code doing this, listing which author have posted in the current category. But get_avatar function not correct working. Im Using Simple Local Avatar Plugin. It is working author.php don't have any problem. But when i use it my this code, it is listing same and wrong author picture(My latest author picture. You can l...
You pull the author ID here: <code> $autid= get_userdata($author)-&gt;ID; </code> So why aren't you using it to get the avatar on the very next line? <code> echo get_avatar( get_the_author_email(), '32' ); </code> <code> get_avatar </code> will accept the ID as a parameter. Try this instead: <code> echo get_avatar( $au...
Wordpress get_avatar function not correct working
wordpress
<code> &lt;?php if ( ! is_admin() ) return; echo 'You should not see this if you're not logged in!'; ?&gt; </code> If you put this in a mu-plugin , and go to your admin, e.g., <code> example.com/wp-admin/ </code> while you are not logged in , should you be able to see the <code> echo </code> ?
You're misinterpreting the <code> is_admin() </code> function. It's not a tag to check whether or not the user is an admin, it's a template tag to check if you're on an admin page. From the Codex : This Conditional Tag checks if the Dashboard or the administration panel is being displayed. This is a boolean function, m...
Is this a WordPress security bug?
wordpress
I want to show some detail information on specific (for e.g. category=3) posts. Therefore I use the following coding: <code> function postinfo_head() { global $post; $script = &lt;&lt;&lt; EOF &lt;script type='text/javascript'&gt; jQuery(document).ready(function($){ $('.post-info').hide(); $('.open-post-info').click(fu...
You shouldn't inject <code> postinfo() </code> in the <code> &lt;head&gt; </code> section (that's what happens when you use the <code> wp_head </code> hook). If you do not want to edit templates, I'd suggest you use the <code> wp_footer </code> hook instead, and append the postinfo to your header div with jQuery, e.g.:...
Insert specific information to a posts of a predefined category
wordpress
I have setup a custom post type with the slug "interview" and it is working fine. I am trying to change the slug to "magazine/interview" but I keep getting 404 errors when I try to access the posts that are already there. Is there any specific trick to set a slug with "/" characters in it?
Make sure to flush rewrite rules after changing the permalink structure, this can be done by visiting the <code> Settings &gt; Permalinks </code> page in admin.
Wordpress custom post type with folder structure in slug
wordpress
I'm trying to optimize the code of my site . I wanted to know if it was possible to give automatically a title to a new post without having to do it manually. I have a website of video games. Before posting a review, I first need to create the plug of this game with all the information (publisher, developer, pc configu...
If you can grab your data early enough you can do this: <code> function alter_title($t) { return 'altered-title'; } add_filter('pre_post_title','alter_title'); add_filter('pre_post_name','alter_title'); </code> That will change the title and the slug before the post is saved. Of course, you need to work out some logic ...
Register a title automatically with a relationship field
wordpress
I've created a custom <code> content.php </code> and removed any comments on the <code> content.php </code> page then i changed the <code> sharing-service.php </code> from jetpack and added <code> comments_popup_link </code> there: <code> // Wrapper $sharing_content .= '&lt;div class="sharedaddy sd-sharing-enabled"&gt;...
You could probably just buffer the output from comments_popup_link in a separate function. <code> function get_comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) { ob_start(); comments_popup_link( $zero, $one, $more, $css_class, $none ); return ob_get_clean(); } </code>
strange behavior with comment position
wordpress
Is there a way to display shortcode content outside of the_content? I am building a custom theme who's theme options includes two text boxes that can be displayed on the front page. I want to be able to display shortcode content placed in these text box options. The theme uses files from the Options Framework.
You can use the function <code> do_shortcode() </code> for use shortcodes outside fomr default content. You can also parse this in your function, there get the output of your textfields, like the follow example for a custom field: <code> if ( get_post_meta( $post-&gt;ID, 'cfield', TRUE ) ) echo do_shortcode( get_post_m...
display shortcodes outside of the_content
wordpress
I have recently starting integrating the wordpress customizer into my theme. Given the fact that i already had a theme options page, i use these values as default values of my new options (in the add_setting parameter). All my new options are held into a variable called 'theme_options' which is an array of values. The ...
I believe that all you need to do is pass defaults to <code> get_option </code> <code> function init_theme_options() { // check to see if theme options are set // Not sure how your options are organized but... $defaults = array( 'opt1' =&gt; 'stuff1', 'opt2' =&gt; 'stuff2' ) $theme_options = get_option('theme_option_na...
Initialize WordPress customizer variables
wordpress
I'm writing a plugin to add some extra contents that contain the permanent link to the (single) post. <code> function abcd_add_contents($content) { $extra_content = the_permalink(); if (is_single()) { $content .= $extra_content; } return $content; } add_filter('the_content', 'abcd_add_contents'); </code> <code> the_per...
globalize <code> $post </code> to get the current post's data. also, you want <code> get_permalink </code> , which returns the permalink, rather than <code> the_permalink </code> , which directly echoes the permalink. <code> function abcd_add_contents($content) { if (is_single()) { global $post; $extra_content = get_pe...
How to get the permanent link in a plugin?
wordpress
I use the <code> load_textdomain </code> action hook to list all active localization text domains with corresponding path to translation files. <code> function mo_location( $domain, $mofile ) { if ( !is_array($GLOBALS['moloc']) ) $GLOBALS['moloc'] = array(); $GLOBALS['moloc'][$domain] = $mofile; } add_action( 'load_tex...
The <code> default </code> text domain is registered in <code> wp_load.php </code> before plugins are loaded. See the function <code> wp_load_translations_early() </code> . So when you register your action callback, the text domain has been loaded already. For an alternative way to list all registered text domains see ...
Action hook load_textdomain $domain variable
wordpress
How can I list the authors of posts in a category in WordPress? On my blog have three authors and I want to list who written the posts in a category. For example: <code> CAT NAME: INTERNET AUTHOR: JOHN, DOE, ALEX CAT NAME: TECH AUTHOR: JOHN CAT NAME: CODE AUTHOR: ALEX </code>
I found a solution. CODE: <code> &lt;?php $cat_arr = get_categories(); // Get the list of Categories foreach ($cat_arr as $cat_obj) { $term_id = $cat_obj-&gt;term_id; // Print the Name ?&gt; &lt;br&gt; CAT NAME: &lt;?php echo $cat_obj-&gt;name ?&gt;, AUTHOR: &lt;?php // Get all Posts of that Category $posts = get_posts...
List the authors that have written posts in a category
wordpress
Not sure if "sanitizing" is really the correct phrase to use for this but it was the best one I could think of...anyways, here is the problem: My function works great like so... <code> // add category id to body &amp; post classes function category_id_class($classes) { global $post; foreach((get_the_category($post-&gt;...
Just use <code> $category-> slug </code> instead of <code> $category-> cat_name </code> . Slugs are already lowercase and with dashes instead of spaces.
Need help "sanitizing" a custom function that pulls category slug into body class
wordpress
I am having issues understanding the worlds most simplest concept when it comes to building a single.php file and using pagination. The code bellow shows a wordpress loop, its contents and then finally the pagination. How ever, the pagination does not show up for me and looking at twenty 10 theme shows this is how you ...
You need <code> next_post_link </code> and <code> previous_post_link </code> , not <code> next_posts_link </code> and <code> previous_posts_link </code> . See the plural on the last two? The ones with the 's' are for archive pagination. The ones without it are for single post to post pagination.
Pagination issue with Single.php
wordpress
I have a custom-built website which pulls data from WordPress. I've included <code> wp-blog-header.php </code> in my page and it is all set, I can get my posts, featured image, titles, anything I want, wherever I want. Now I'd like to add new languages to my website, so I've set up multisite so I can have one site for ...
You can use the <code> switch_to_blog() </code> function to switch the scope to a specific site and access data from that site: <code> require_once( '/path/to/wp-load.php' ); switch_to_blog( 3 ); $option = get_option( 'admin_email' ); restore_current_blog(); </code> Also, you should use <code> wp-load.php </code> when ...
Retrieving data from specific multisite blog
wordpress
I am filtering the_permalink to return a custom structure <code> function append_query_string($url) { $url_endpoint = get_permalink(); $url_endpoint = parse_url( $url_endpoint ); $url_endpoint = $url_endpoint['path']; return '#!'. $url_endpoint; } add_filter('the_permalink', 'append_query_string'); </code> the filter a...
If we look at <code> get_permalink </code> in source , we'll see the various filters applied to this function. For posts, it's <code> post_link </code> , for custom post types, it's <code> post_type_link </code> , for pages it's <code> page_link </code> , and attachments is <code> attachment_link </code> .
get_permalink vs the_permalink
wordpress
I am trying to retrieve all the images from the <code> Gallery </code> of a page in the order they are set in the backend. So far I have: <code> $my_wp_query = new WP_Query(); $all_wp_pages = $my_wp_query-&gt;query( array( 'post_type' =&gt; 'attachment', 'post_parent' =&gt; 54, 'post_mime_type' =&gt;'image', 'post_stat...
When you create a gallery via the 3.5 media manager, <code> menu_order </code> is no longer used to save the order of the images, the order only exists in the shortcode you insert when you click the <code> Insert Gallery </code> button, via the <code> ids= </code> attribute. This is to accommodate the fact that you can...
How to get Page/Post Gallery attachment images in order they are set in backend using WP_Query()?
wordpress
I am trying to generate a menu using wp_nav_menu. My expected output is this: <code> &lt;!-- Main Menu --&gt; &lt;div class="navbar navbar-blue navbar-fixed-top" style="margin-top:74px"&gt; &lt;div class="navbar-inner"&gt; &lt;div class="container"&gt; &lt;a class="btn btn-navbar" data-toggle="collapse" data-target=".n...
You want to modify the <code> start_el </code> method as you did the <code> start_lvl </code> one. At its most basic it would mean altering this line : <code> $item_output .= '&lt;a'. $attributes .'&gt;'; </code> To look like this one: <code> $item_output .= '&lt;a class="dropdown-toggle" data-toggle="dropdown"'. $attr...
Adding attributes to link in wp_nav_menu using custom Walker function
wordpress
I moved a WordPress site to another server and everything is working well, minus the fact that I can't seem to change the settings in Privacy. When I click on "allow search engines to index this site", the radio button automatically switches back to "ask search engines not to index this site". Also, the Privacy Setting...
The privacy page was removed in WordPress 3.5. Go to <code> wp-admin/options-reading.php </code> and set search engine visibility there.
Where have the Privacy Settings gone in WordPress 3.5?
wordpress
I've just realized that the traditional <code> uninstall.php </code> file along a plugin is not working in Multisite. <code> if ( !defined( 'WP_UNINSTALL_PLUGIN' ) ) exit(); delete_option( 'plugin_option_name' ); </code> This doesn't delete the sub-sites options in all <code> wp_SITE-ID_options </code> tables. Is there...
Searching inside all <code> uninstall.php </code> files that I have in my hard-drive, I've found two that had the function <code> is_multisite() </code> : User Role Editor and Add Code to Head . Both use a <code> $wpdb </code> loop. Simplified: <code> &lt;?php /** * Plugin Uninstall Procedure */ // Make sure that we ar...
Uninstall script for a plugin in Multisite
wordpress