question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
After installing the Disqus plugin, their JavaScript code started popping up as plain text on my site in several places. My hypothesis is that it pops up at the end of any loop involving <code> the_post() </code> . This is one of them. Here's a snippet from my <code> front-page.php </code> : <code> foreach ($terms as $...
On some themes the Disqus code is rendered at a bad position within the loop. Go to the Disqus plugin within Wordpress, click the "Advanced options" tab, and then check "Output javascript in footer". That should fix this.
Disqus plugin outputs script as literal text
wordpress
I'm working on a Custom Post Type sorted on a Custom Field. No problem when I list out the posts. But when I go to the single post page for one of these, I want the Prev and Next navigation links to take us to the prev/next posts in the sort order dictated by the Custom Field. By default, WP orders them by post date. C...
For previous and next post links to work, you need to hook on to the <code> get_*_post_* </code> filters and modify the query to actually sort the posts using your custom field. I hope the code below will work for you. For Previous post link <code> add_filter('get_previous_post_join', 'wpse96670_get_previous_post_join_...
Custom Post Type Navigation on Custom Field
wordpress
I would like that each category link to the last post of each category. category 1 ----> link to the last post of category 1 category 2 ----> link to the last post of category 2 category 3 ----> link to the last post of category 3 How can I do it?
You can filter <code> category_link </code> and replace the URL here. I have used the newest post in the following example, because first could also mean the oldest and that sounds … strange. :) <code> add_filter( 'category_link', 'wpse_96677_cat_link_to_first_post', 10, 2 ); function wpse_96677_cat_link_to_first_post(...
Link each category to last post
wordpress
Here is the code on how to delete all dashboard widgets - the default, and plugin widgets but I want to change the code to only delete custom dashboard widgets not the default ones. <code> // Create the function to use in the action hook function remove_dashboard_widgets() { global $wp_meta_boxes; if ( !array( $wp_meta...
The built-in dashboard widgets are not marked somehow, you have to use a fixed list: <code> 'dashboard_right_now', 'dashboard_plugins', 'dashboard_quick_press', 'dashboard_recent_drafts', 'dashboard_recent_comments', 'dashboard_incoming_links', 'dashboard_primary', 'dashboard_secondary' </code> So your code should test...
Delete Custom Dashboard Widgets
wordpress
I am working on a plugin for which I will have to develop a backend page similar to the built-in "Users" one, in the sense that it will be basically do the same things: list the existing users ( using the <code> WP_List_Table </code> class ), edit / remove, and add new ones as well. The only difference is that it will ...
Always use the existing functions, if those functions do what you need. That way, your code has the best chance of staying functional as the Core changes. If you make direct queries to the database then you have to keep track of changes to the database and alter your code accordingly. Using Core functions also means th...
Wp-admin Custom User Management
wordpress
I have the line of code below with the intention to display the called menu in every other page except the home page but it still shows up on the home page. Any ideas what the problem could be. <code> &lt;?php if (!is_home()) { wp_nav_menu (array('menu'=&gt;'sideBar','menu_class' =&gt; 'navbar')); } ?&gt; </code>
Is your home page blog index or static page? <code> is_home() </code> is meant to check if we are on blog index (latest posts), while <code> is_front_page() </code> checks if home is static page set in Settings > Reading .
Conditional menu display
wordpress
I am running a site for a German NGO under the domain <code> sub.example.org </code> . Recently, I added <code> sub.example.ch </code> for its Swiss spin-off. Both (sub-)domains are pointing to the same physical location, a WP install ( not multisite). I have it setup such that <code> sub.example.ch/register </code> , ...
You could filter the option requests for the host. In your <code> wp-config.php </code> below the line … <code> require_once ABSPATH . 'wp-settings.php'; </code> … add the following lines: <code> add_filter( 'pre_option_home', 'set_current_host' ); add_filter( 'pre_option_siteurl', 'set_current_host' ); function set_cu...
Two (or more) parallel (sub-)TLDs that are retained when surfing the site / dynamically set the site address?
wordpress
When wordpress sidebar outputs any particular <code> registered sidebar </code> it loop through all widgets that assigned through it and outputs it (i guess). Is is possible to hook into the loop and add some content, say I want to add a ad code every three widgets . What I have tried? Unable to find any leads. Tried t...
Hook into <code> 'dynamic_sidebar' </code> and count how often it is called. You get the current active sidebar with <code> key( $GLOBALS['wp_registered_sidebars'] ) </code> . <code> add_action( 'dynamic_sidebar', 'wpse_96681_hr' ); function wpse_96681_hr( $widget ) { static $counter = 0; // right sidebar in Twenty Ten...
Hooking Into Widget Output Loop
wordpress
Trying to figure out an issue a fellow programmer is having. I was wondering if the <code> functions.php </code> file get called at all when you do admin side AJAX? I know that when you do an AJAX call a part of WP gets loaded up to process the call and send back a response. Is the <code> functions.php </code> file inc...
<code> admin-ajax.php </code> loads <code> wp-load.php </code> : <code> /** Load WordPress Bootstrap */ require_once( dirname( dirname( __FILE__ ) ) . '/wp-load.php' ); </code> <code> wp-load.php </code> loads <code> wp-config.php </code> , and there <code> wp-settings.php </code> is loaded. And here we find this: <cod...
Does the functions.php file ever get called during an AJAX call? Debug AJAX
wordpress
I have the inconsistency in post published time. For example, as I published a post on April 20nd 9pm and it is April 20nd 9:30, wordpress shows it is published one minute ago in the admin end. Also in case, a post is published like 18 hours ago, wordpress says it is published only an hour ago. (it display correct time...
Your computer's time and your server's time may not be exactly synchronized. So you may be seeing some pseudo-issues because of that. I don't know where you are seeing "published 1 minute ago", or anything like that, in the backend. I see a "published on" date and a "last edited" date but those are 'hard' dates not dat...
admin end post published time display not working correctly
wordpress
Hi I have a form that adds attachments to a post, however when the form posts it obviously doesn't show the post with the new attachment echoing "your file has been uploaded". When the user refreshes the page (to try and show their new attachment) the form posts again! Is it possible to either (1) stop the form posting...
Instead of … <code> } else { echo "&lt;p&gt;Your file has been uploaded.&lt;/p&gt;"; } </code> … redirect to another address on success: <code> } else { $new_url = add_query_arg( 'success', 1, get_permalink() ); wp_redirect( $new_url, 303 ); } </code> Status code 303 triggers a GET request : This method exists primaril...
How to stop form resubmission on page refresh
wordpress
I have a get_categories array <code> $args=array( 'orderby' =&gt; 'id', 'order' =&gt; 'ASC', 'taxonomy' =&gt; 'wpsc-variation', 'hierarchical' =&gt; 1, 'hide_empty' =&gt; 0 ); $variationCategories=get_categories($args); </code> I display those categories as a checkbox. <code> foreach($variationCategories as $category) ...
There is already a function in WordPress doing that: <code> wp_terms_checklist() </code> . It is used in the metabox for hierarchical taxonomies in the post editor. Maybe you can reuse that? The following is untested, see it just as a guide please, not as a complete solution: <code> // File where "wp_terms_checklist()"...
Resort get_categories
wordpress
I need to call a sidebar into my header. I've switched to the new twenty twelve theme and created my own child theme. With this new theme I decided to keep things organised and together, so I put my widgets functions, stylesheet and two new sidebar templates (one for header and one for footer widgets) in one folder cal...
Impossible with <code> get_sidebar() </code> . From that function’s body: <code> function get_sidebar( $name = null ) { do_action( 'get_sidebar', $name ); $templates = array(); if ( isset($name) ) $templates[] = "sidebar-{$name}.php"; $templates[] = 'sidebar.php'; </code> So if you pass a <code> $name </code> or any ot...
Call sidebar from a template
wordpress
I'm running WP 3.5.1 and I've a menu with about 100 items. When I add new items to the menu older ones disappear. I'm not running Suhosin or similar stuff. What can be the cause? Note: I'm on a dedicated server.
The following has worked for some users with similar problem: Try to increase the value of the <code> max_input_vars </code> variable in <code> php.ini </code> . This variable was introduced in PHP version <code> 5.3.9 </code> and has the default value of <code> 1000 </code> . You can read more about it in the PHP docu...
Menu Items Disappearing
wordpress
I am trying to put several queries in a shortcode so that I can call them in a page instead of using custom templates. I got my query going but I only see some of the content on the page. The image shows up, the text shows up but none of the html markup is showing up. Is there a Wordpress function that I need to pass t...
When you are constructing the <code> $output </code> variable, you need to consider <code> get_the_post_thumbnail() get_the_excerpt() get_the_content() get_permalink() </code> that return the values instead of <code> the_post_thumbnail() the_excerpt() the_content() the_permalink() </code> that echo the values.
WP_Query in a shortcode
wordpress
On a blog with pingbacks and trackbacks (pings) enabled I want to show just a link with link text and a favicon of the external site in a compact list: no date, no text. How can I do that?
The first you do: separate regular comments and pingbacks. In your <code> comments.php </code> set the type parameter for both: <code> &lt;ol class="commentlist"&gt; &lt;?php // show regular comments wp_list_comments( array ( 'type' =&gt; 'comment', 'style' =&gt; 'ul' ) ); ?&gt;&lt;/ol&gt; &lt;ol class="pinglist"&gt; &...
Compact pingback list with favicons
wordpress
I am working on a WordPress blog for a client. Currently they have around 3,000 posts. The WordPress is installed at <code> /blog/ </code> I need to move the WordPress install to the Root directory but still have the Blog posts show up at <code> /blog/ </code> so after I move the blog, all the Post URLs will remain the...
Create an empty page with the slug <code> blog </code> . Go to Settings/Reading and set that page as Posts page . Go to Settings/Permalinks and set the URL pattern to <code> /blog/%postname%/ </code> . That should do it.
Move WordPress from /blog folder to root but leave post at /blog
wordpress
I'm using <code> wp_query() </code> to get custom posts from the database. I want to list these out as links to the entries, so I'm thinking I could use the slugs. Sadly these don't seem to be included in the <code> wp_query </code> object. Here's my code: <code> $oWP = new wp_query(array( 'post_type' =&gt; 'letters_of...
The slug is already in the post object, it's <code> $post-&gt;post_name </code> . And as you observed, yes, the way to get the post link is <code> get_permalink( $post-&gt;ID ); </code>
Finding a post's slug
wordpress
My wordpress feeds post item looks following: <code> &lt;item&gt; &lt;title&gt;Taste Trail – Lima and Cusco’s Best Eats&lt;/title&gt; &lt;link&gt; http://example.com/taste-trail-lima-and-cuscos-best-eats/&lt;/link&gt; &lt;comments&gt;http://example.com/taste-trail-lima-and-cuscos-best-eats/#comments&lt;/comments&gt; &l...
You could filter <code> 'the_permalink_rss' </code> : <code> add_filter( 'the_permalink_rss', 'wpse_96602_change_feed_item_url' ); function wpse_96602_change_feed_item_url( $url ) { $parts = parse_url( $url ); return $parts['scheme'] . '://' . $parts['host'] . '/#!view' . $parts['path']; } </code> But … I strongly reco...
Change the link URL in default RSS feeds
wordpress
Trying to list all Custom Post Type titles based on filtered Custom Taxonomy Terms I am getting the list of all post titles instead of getting the list of Queried post. Here is the code I am using: <code> &lt;?php $loop = new WP_Query( array( 'post_type' =&gt; 'photos', 'technique' =&gt; 'zevar', 'post_child' =&gt; 0, ...
The <code> {tax} =&gt; {term} </code> pattern is deprecated as of 3.1 you should be using <code> tax_query </code> , but your code should still work for some undetermined length of time. <code> post_child </code> is not a parameter that <code> WP_Query </code> accepts. I don't know what you expect that to do but at bes...
Cant' Display Custom Post Type Title Base on Tax Terms
wordpress
I created a custom meta box with a textbox where the user can enter a custom value in as an additional identification tag. I thought I had it right but when I try to retrieve the value it is giving me the post ID instead of the custom value that was input. I am sorry if the post gets too long but I want to be thorough....
Please take some time to read the Codex. <code> the_ID </code> <code> echo </code> s content . That means that the ID is never being passed to <code> get_post_meta </code> . It is just <code> echo </code> ed in place. From the same Codex Page: Note: This function displays the ID of the post, to return the ID use get_th...
Get post meta retrieving wrong value
wordpress
I've been changing the way that the Single product page looks. I've moved a few things about by hooking into Woocommerce and also editing the css. Out of the box the single product page shows the short description (described as woocommerce_template_single_excerpt in the content-single-product.php file) next to the prod...
Slightly different fix provided by Woocommerce so I thought I should include it here: In templates/single-product/short-description.php where it says: <code> $post-&gt;post_excerpt </code> Replace this (2 occurrences) with; <code> $post-&gt;post_content </code> Thanks
Changing Woocommerce Product Description
wordpress
I can't get <code> WP_Query </code> to work in my custom-post-type archive page. Can someone please tell me what I'm doing wrong? I would appreciate any help. Here's the code in <code> archive-bulletin.php </code> : <code> &lt;?php get_header(); //wp_reset_query(); wp_reset_postdata(); $q = new WP_Query("post-type=bull...
If this is the main query, you shouldn't be creating a new query at all, just run the normal loop and you will see the posts from your CPT. The reason your custom query isn't working is that <code> post-type </code> is not a valid parameter, it's <code> post_type </code> (underscore, not hyphen). If your goal is to ult...
How to use WP_Query in a CPT achive page?
wordpress
I am using custom post types in a theme optimized for web radios (custom theme). I added a custom post type called "Radio Shows" and registered two custom taxonomies: one hierarchical (like default "categories", I named it GENRE) and the other is not (like "tags", I named it INSTRUMENTS). I've managed to get that custo...
Use <code> the_terms() </code> : <code> the_terms( $id, $taxonomy, $before = '', $sep = ', ', $after = '' ) </code> So in your loop: <code> if ( 'radio-shows' === get_post_type() ) { the_terms( get_the_ID(), 'genre' ); the_terms( get_the_ID(), 'instruments' ); } else { the_category(); the_tags(); } </code>
Display Custom Taxonomy
wordpress
Having a hard time composing a searchable query, so I apologize in advance if this has been covered. I know you can add WooCommerce products to a page or post via short code, but I have one section of my site where it's displaying from theme settings and PHP template only. So my question is, how can I display a product...
Use do_shortcode() . For example, in a template, if you were wanting to display products specifically by ID: <code> &lt;?php echo do_shortcode('[products ids="1, 2, 3, 4, 5"]'); ?&gt; </code> WooCommerce comes with several shortcodes which can be used to insert content inside posts and pages: http://docs.woothemes.com/...
Displaying a WooCommerce product via PHP
wordpress
I have installed a Mathjax plugin on my local wordpress installation, and the plugin works fine. However, I can't get it to show Latex in-text; it creates an own line for every latex formula. I end up with pages like this (this is an extreme example to get my point across better :)): How can I make it work to show Late...
To create an inline formula in LaTeX we can use single dollar signs <code> $ </code> : <code> This formula $x=y+z$ is inline. </code> To display math on its own line, we can use double dollar signs <code> $$ </code> : <code> $$ a = b + c $$ </code> Here is an example with Simple Mathjax installed: This will be displaye...
Using MathJax in text
wordpress
How to create a permalink structure which finish by: <code> /category-name/post-name/ </code> Instead of: <code> /category-slug/post-name/ </code> By default, Wordpress is offering <code> %category% </code> tag strucure as "A sanitized version of the category name (category slug field on New/Edit Category panel". How c...
I did not test this, but this should do what you want. Put the following in your <code> functions.php </code> : <code> add_filter('rewrite_rules_array', 'category_name_rewrite_rule'); function category_name_rewrite_rule($rules) { $new_rules = array(); $categories = get_categories(); foreach ($categories as $category) {...
Use the category name instead of category slug in permalinks
wordpress
Case: When a user submits a (Gravity)form, the plugin automatically generates an unique entry ID for that specific form. In my case the form settings only allow user to submit the form once, and only if user is registered. When user submits the form, a page is created with the content of the form. The URL of that page ...
You can use the <code> gform_after_submission </code> hook [1] to add the Entry ID (and probably the Form ID to minimize confusion if you have multiple forms) to the user's meta information using <code> add_user_meta() </code> . <code> &lt;?php add_action( 'gform_after_submission', 'wpse96468_map_user_to_entry', 10, 2 ...
How to get the Gravityform entry ID from current user's form submission?
wordpress
There are a lot of answers on how to count users posts by using: <code> &lt;?php if ( is_user_logged_in() ) { global $wpdb; $user = wp_get_current_user(); $where = get_posts_by_author_sql( 'page', true, $user-&gt;ID ); $count = $wpdb-&gt;get_var( "SELECT COUNT(*) FROM $wpdb-&gt;posts $where" ); ?&gt; //option 1 &lt;h2&...
Look what <code> count_user_posts() </code> does inside and change the post type parameter: <code> global $wpdb; // 'page' is the important part here $where = get_posts_by_author_sql('page', true, $userid); $count = $wpdb-&gt;get_var( "SELECT COUNT(*) FROM $wpdb-&gt;posts $where" ); </code> Then you change your snippet...
How to count current user's pages?
wordpress
In Wordpress, I would like to add a custom styling to the <code> &lt;blockquote&gt; </code> elements, replacing Wordpress' default usage by using a function (or however is easiest). When using the WYSIWYG editor, highlighting text, and then clicking the "blockquote" button, I would like the highlighted text to be wrapp...
Put this in your <code> functions.php </code> : <code> add_shortcode('my_blockquote', 'my_blockquote'); function my_blockquote($atts, $content) { return '&lt;div class="span3 quote well"&gt;'.PHP_EOL .'&lt;i class="icon-quote-left icon-2x pull-left icon-muted"&gt;&lt;/i&gt;'.PHP_EOL .'&lt;blockquote class="lead"&gt;'.$...
Custom HTML markup
wordpress
The code below is the 2nd of 4 loops in "page-balls.php". Everything else is working correctly. I'm trying to display a tennis ball graphic if the post being retrieved has a the term "tennis-ball" term. It's not working. Is this because the PAGE does not have the term TENNIS-BALL? How can I make this work correctly? <c...
The codex on <code> is_tax </code> : This Conditional Tag checks if a custom taxonomy archive page is being displayed. That is not the condition you want to check for. Take a look at the <code> has_term </code> function and use it like so: <code> if( has_term( 'tennis-ball', 'ball-types', $post-&gt;ID ) ) { /* SHOW THE...
Problem with is_tax in WP_Query loop
wordpress
I'm upgrading multisite to 3.5.1 and it did not allow me to do automatic upgrading I see this message: "To perform the requested action, WordPress needs to access your web server. Please enter your FTP credentials to proceed. If you do not remember your credentials, you should contact your web host." So I add the FTP c...
You need to... ... have your files and folders owned by your user. If you have <code> sudo </code> privies with your SSH access this should be easy to accomplish. <code> sudo chown -R user ./wordpress_directory </code> ... have your files and folders, at least the ones in <code> wp-content </code> , in the same group a...
Upgrade Wordpress multisite to 3.5.1 problems
wordpress
I have a small problem with a code that works most of the time. I just discovered it cannot be used when I bulk edit custom post type. If I'm on individual post page and hit publish, the custom post type gets published and the user meta gets updated. If I use the bulk edit to publish many posts at once, the user meta i...
Try using the $post parameter: <code> add_action( 'pending_to_publish', 'sa_ads_count' ); function sa_ads_count( $post ) { // use the $post variable here, not the missing global. } </code>
Update post meta on bulk edit / update
wordpress
I am trying to figure out how to add a dropdown widget to the post page. The reason I ask is because I would like to be able to have a few different post classes that the user can select while making a post that they can select. I figure I can use post_class and define a few different classes and allow the user to use ...
Since this is very similar to post formats (see post-formats ) I would use a custom taxonomy. That makes it easy to control the access level, and you get the meta box without writing extra code. Then you insert the new post classes with a simple filter. Your theme must use the function <code> post_class() </code> – of ...
How can I add dropdown widget/box to admin post page?
wordpress
I have a WordPress parent theme that uses a custom post type called <code> portfolio </code> , which I'd like to change to <code> property </code> . I'd like to have all of the contextual elements changed to show <code> property </code> like, <code> "show properties" </code> , <code> "add new property" </code> , <code>...
<code> $wp_post_types </code> is a global array that holds <code> post_type </code> objects, which in turn have a <code> labels </code> property. You can change <code> $wp_post_types[$post_type]-&gt;labels </code> after the parent theme has set the CPT. Add higher priority to <code> init </code> hook. Add the following...
Change labels of custom post type via child theme
wordpress
I'd like to to extend the <code> wp_users </code> table in my WordPress' database. Why? I want people to add more information about themselves when they sing up at my website. I know how to extend it, but I'm afraid that when WordPress needs an update the <code> wp_users </code> table, i.e. the columns I added, will be...
There are far better ways of doing this. Instead of modifying the user table, make use of User Meta. It has a dedicated table, and works the same way as post meta, but for users. add_user_meta get_user_meta update_user_meta There are many tutorials explaining how to add additional fields to the user profile using User ...
Extend the wp_users table
wordpress
I have a search form that I want to place in multiple pages (it will be in different header types) I do this by using the 'get search form' function. On my Search form I have radio sections listing two custom post types 'poster' and 'house'. I have two different search pages for each post type. I want them to be separa...
This is my Solution, I used Onclick attributes for the radio buttons to change the 'actions' of elements within the form. <code> &lt;form id="searchme" action="&lt;?php echo site_url(); ?&gt;/postersearch" method="get"&gt; &lt;ul class=" four columns inline-list offset-by-one"&gt; &lt;li&gt;&lt;label for="radio4"&gt;&l...
Two Search pages, One search form
wordpress
I have this twitter share button that pulls 100 characters from the content of the post and its URL for the twitter share. <code> &lt;a class="popup" href="http://twitter.com/share?url=&lt;?php echo urlencode(get_permalink($post-&gt;ID)); ?&gt;&amp;amp;text=&lt;?php the_content_limit(100, "");?&gt;"&gt; &lt;img src="ht...
You are sending <code> text </code> unencoded. <code> urlencode </code> that just like you do the permalink. <code> &lt;a class="popup" href="http://twitter.com/share?url=&lt;?php echo urlencode(get_permalink($post-&gt;ID)); ?&gt;&amp;amp;text=&lt;?php echo urlencode(the_content_limit(100, ""));?&gt;"&gt;&lt;img src="h...
w3c validation problem - Twitter share button pulling content
wordpress
I'm writing a plugin that creates posts in bulk. I provide a way for the user to set certain parameters of the created posts beforehand. But it would be useful to use the WordPress default "All Posts" ( <code> edit.php </code> ) interface to fine-tune the details after the posts are created. I had a look at the <code> ...
It can be achieved using <code> pre_get_posts </code> . It is important to prefix all your variable names, <code> id </code> seems not be in the reserved terms list , but anyway this practice avoids any unforeseen bug. <code> /** * Usage: * http://example.com/wp-admin/edit.php?my_pids=4088,4090,4092,4094 */ add_filter(...
Admin Posts List (edit.php) by post IDs
wordpress
I've installed WordPress for my school's website. I have a task of creating a file archive, an uploader and a file viewer for the website. The file archive would store files on the server, "in the background". The uploader would enable users to upload files and tag them. And a file viewer would allow users to view and ...
These are actually two questions. The second question – how to add categories to attachments – stackexchange-url ("is already answered"). How to restrict uploading attachment to a specific role? The capability to do that is named <code> upload_files </code> in WordPress. Some roles have this capability by default: auth...
How to create a file archive in WordPress?
wordpress
Is there a WP plugin that binds jQuery GalleryView to the stock WP Gallery? I love the appearance of GalleryView, but I don't want to have to use an external image &amp; gallery database like NextGen. I just want to use the stock WP Gallery, stock WP media library, and display images attached to a particular post or pa...
I'm afraid there's no plugin, but using jQuery GalleryView is not that hard actually. Download Download jQuery GalleryView and put the <code> css </code> and <code> js </code> folders inside a new folder <code> galleryview </code> in your theme's folder. Setting Up the List jQuery GalleryView needs an unordered list so...
GalleryView binding for WP Gallery, without NextGen
wordpress
Is there a way to use a custom PHP template for search results of a custom post type. I know that you can have specific archive and category templates for custom post types. For example, archive-custom.php. But, the same doesn't work for search.php. Any suggestions?
According to stackexchange-url ("this answer") of yours, you can do the following inside your <code> search.php </code> : <code> if (isset($_GET['post_type'])) get_template_part('search', $_GET['post_type']); else // no post_type given </code> Then you have to set up the <code> search-{post_type}.php </code> files. If ...
Customize Search Results for Custom Post Type
wordpress
Apparently this is built into WP somwhere since going to mysite/wp-login.php takes me to mysite/&lt;wp path&gt;/wp-login.php (same for wp-admin and I presume other paths). The problem is, I don't like this functionality. My paths are intentionally not the default in order to make them less accessible to automated brute...
I have hidden that in stackexchange-url ("this answer"), so I duplicate it here as a separate solution: <code> &lt;?php # -*- coding: utf-8 -*- /* Plugin Name: No admin short URLs */ remove_action( 'template_redirect', 'wp_redirect_admin_locations', 1000 ); </code>
How can I prevent redirects from mysite/page to mysite/wp path/page?
wordpress
I have three custom post types set up, <code> articles </code> , <code> videos </code> and <code> photos </code> . I am using standard categories for these post types, and sharing the categories across all post types. I am trying to create a nav menu for each post type, listing the categories, that should follow the fo...
Put the following in your <code> functions.php </code> : <code> function wp_list_categories_for_post_type($post_type, $args = '') { $exclude = array(); // Check ALL categories for posts of given post type foreach (get_categories() as $category) { $posts = get_posts(array('post_type' =&gt; $post_type, 'category' =&gt; $...
Only list categories that contain posts of a specific custom post type
wordpress
Usually I would get a post title no problem, however now I need to achieve something like this: The Example is written for this title As you can see two words are links in the title, another problem is that there could be any number of links, as it will depend on a content. How can I achieve this? will I have to use ad...
The easy way of doing this is to not display the title on your page template, and have a h1 header as the first thing in your content.
Best way to achieve multiple links in a post title
wordpress
I'm currently working on building this site: http://2013.whitehallrow.com/ I would like to centre the menu items so that there isn't the large gap after "Row Club" on the right. I've tried to locate the section in style.css that deals with the menu, but I can't find it... how do I do this?
on the ".main-navigation li" (line 1487) from css, you put {padding: 0 24px; margin:0px; position: relative;}, and remove anything else. This should do the trick. --- or --- you move the top and bottom borders on the menu-nav-bar-container div, and you remove the borders and width from the ul. This shoud do the trick t...
How to centre menu items on horizontal nav bar? (e.g. make margins equal)
wordpress
Intro: I have a webpage that is not part of wordpress. I have incorporated the wp blog posts, by putting The Loop in the page's code. This works, it displays the current posts and their following posts up to 3, which is what I set in the wp general options. On this, non-wp, webpage, I have a sidebar, dubbed "history". ...
You have to loop through that part of the code to get more posts: <code> $args = array( 'posts_per_page' =&gt; -1 ); $the_query = new WP_Query( $args ); &lt;?php if ($the_query-&gt;have_posts()) : ?&gt; &lt;?php while ($the_query-&gt;have_posts()) : $the_query-&gt;the_post(); ?&gt; ...&lt;your code&gt;... &lt;?php endw...
How to display following posts titles in separate div's on a separate webpage
wordpress
I have the following query, trying to fetch the latest sticky posts but exclude the current one: <code> $sticky = get_option('sticky_posts'); rsort( $sticky ); $sticky = array_slice($sticky, 0, 3); query_posts( array( 'post__not_in' =&gt; array($post-&gt;ID), 'post__in' =&gt; $sticky, 'caller_get_posts' =&gt; 1, ) ); <...
This should do: <code> // Get sticky posts $sticky = get_option('sticky_posts'); rsort($sticky); $sticky = array_slice($sticky, 0, 3); // Check if current post is inside foreach ($sticky as $key =&gt; $value) if ($value === $GLOBALS['post']-&gt;ID) { // ... and remove unset($sticky[$key]); break; } $query = new WP_Quer...
Exclude current sticky post
wordpress
I'm having a hard time determining the first direction to take with this. I'm trying to write a plugin that allows users to pick a location for a post to be inserted into the homepage. For example a user can 'sticky' an old post to the 2nd location on their front page. My problem is I don't know how to insert a post in...
This took a bit of trial and error but I think I got it. I was getting an infinite loop until I added <code> suppress_filters </code> . After that it was short work. <code> function insert_post_wpse_96347($posts) { global $wp_query; $desired_post = 151; if (is_main_query() &amp;&amp; is_home() &amp;&amp; 0 == get_query...
Insert/sticky specific post into Loop at specific location
wordpress
So I added my videos custom post type to my rss feed via this code. <code> //Add videos custom post type function myfeed_request($qv) { if (isset($qv['feed']) &amp;&amp; !isset($qv['post_type'])) $qv['post_type'] = array('post', 'videos'); return $qv; } add_filter('request', 'myfeed_request'); </code> Is there a way to...
Filter <code> the_content_feed </code> : <code> add_filter( 'the_content_feed', 'wpse_96342_add_video' ); function wpse_96342_add_video( $feed_content ) { // fetch post meta // add to content return $feed_content; } </code>
Adding a custom post type meta field to rss
wordpress
Hello WordPress Users, I'm stuck with a problem building my wordpress website and I can't figure out what to do about it. Currently I'm showing 2 posts form the category 'News' at the page 'News'. At the bottom of this page I want a Prev/Next button that shows the next or previous 2 posts from the same category. So I w...
Pass <code> Paged </code> into parameter array of <code> query_posts </code> You should set <code> get_query_var( 'paged' ); </code> if you want your query to work with pagination. <code> $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args_news= array( 'cat' =&gt; 1, 'posts_per_page' =&gt; 2, 'orderby...
Next/Prev posts on same page
wordpress
I'm trying to do something like this: stackexchange-url ("Hide a page in the admin end without a plugin?") However, I don't want to hardcode the page-ids. I want to get the page id's based on template-name. <code> $pages = get_posts(array( 'post_type' =&gt; 'page', 'meta_key' =&gt; '_wp_page_template', 'meta_value' =&g...
Use the parameter <code> 'fields' </code> : <code> $pages = get_posts( array( 'post_type' =&gt; 'page', 'meta_key' =&gt; '_wp_page_template', 'meta_value' =&gt; 'product.php', 'fields' =&gt; 'ids' ) ); </code> Not tested, but it should fetch just the IDs.
get page id's - not get pages?
wordpress
I have query vars defined in functions.php using: <code> add_filter('init', 'add_query_vars'); function add_query_vars() { global $wp; $wp-&gt;add_query_var('profession'); } </code> Until now, to retrieve the query var in page templates, I have been using <code> $profession = get_query_var('profession'); </code> . A si...
<code> get_query_var() </code> is a wrapper for <code> $wp_query-&gt;get($var); </code> . But the global <code> $wp_query </code> is not always identical to the one set up during the request. That’s the query_posts() </code> . And other plugins can overwrite these variables unintentionally too. I have seen plugins putt...
get_query_var vs global query variables?
wordpress
Ive based this on the twenty twelve theme, and copied a tutorial and built the following searchbox:- <code> &lt;header&gt; &lt;h1 class="page-title"&gt;&lt;?php printf( __( 'Search Results for: %s', 'PCDConsulting' ), '&lt;span&gt;' . get_search_query() . '&lt;/span&gt;' ); ?&gt;&lt;/h1&gt; &lt;/header&gt; &lt;?php /* ...
Crystal Ball Programming and Why Your Searchbox Failed Your form fails because of this: <code> action="&lt;?php bloginfo('template_url'); ?&gt;/MilkNHny/search.php" </code> You should never directly call a template via URL. Your template assume the WordPress environment has been loaded, which is a fair assumption. Howe...
Search Form Based On Tutorial Not Working
wordpress
I have the following code: <code> $data = new WP_Query('s=a'); </code> and the print_r returns the following data: <code> WP_Query Object ( [query_vars] =&gt; Array ( [s] =&gt; a [error] =&gt; [m] =&gt; 0 [p] =&gt; 0 [post_parent] =&gt; [subpost] =&gt; [subpost_id] =&gt; [attachment] =&gt; [attachment_id] =&gt; 0 [name...
It's okay here. My request: <code> SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND (((wp_posts.post_title LIKE '%a%') OR (wp_posts.post_content LIKE '%a%'))) AND (wp_posts.post_password = '') AND wp_posts.post_type IN ('post', 'page', 'attachment') AND (wp_posts.post_status = 'publish') ORDER BY wp_p...
WordPress | WP_Query does not return anything with s=a
wordpress
I am trying to enqueue a couple of js files using something like this code: <code> function scripts_function() { wp_register_script('mapbox', 'http://api.tiles.mapbox.com/mapbox.js/v0.6.7/mapbox.js'); wp_enqueue_script('mapbox'); wp_register_script('myscript', plugins_url( 'my-js-file.js' , __FILE__ )); wp_enqueue_scri...
I'm not sure but it might have something to do with the <code> html5blank_protocol_relative() </code> function used by HTML5 Blank Theme . You could try removing the filters at L# 382 &amp; 383 of the <code> functions.php </code> file . <code> // Protocol relative URLs for enqueued scripts add_filter( 'script_loader_sr...
enqueue_script doesn't work with HTML5 blank theme
wordpress
Is there any possibility to pass some PHP variables in javascript so I can use them later? Only in <code> single.php </code> . I heard about <code> wp_enqueue_scripts </code> but with that it is neccesary to declare a path to a JS file, but I don`t need one.
Best practice method Have a look at <code> wp_localize_script </code> , which is meant to do exactly that. But it does require previous usage of <code> wp_enqueue_scripts </code> , hence you will need to move your JS to a separate file indeed. It will be worth those few minutes of effort though, for sure. <code> functi...
Pass PHP variable to javascript
wordpress
I changed up my theme to work what I think is the "proper" way. After reading in the codex and seeing things on this site. I started from scratch. loaded the 2012 theme. Made two pages. Home and blog. I set the homepage to have the default 2012 front-page.php template. then in the settings-> reading I set static front ...
I fixed part of my issue by setting the <code> "posts_per_page" =&gt; -1 </code>
pages won't show on front page using loop or pre_get_posts
wordpress
I'm using the standard WordPress search form to search a custom post type. Here is my code: <code> &lt;form role="search" method="get" id="searchform" action="&lt;?php echo home_url( '/' ); ?&gt;"&gt; &lt;input type="hidden" name="post_type" value="attorney" /&gt; &lt;input type="text" value="" name="s" /&gt; &lt;input...
I didn't test the code below, but I guess it works. <code> /** * Search SQL filter for matching against post title only. */ function __search_by_title_only( $search, &amp;$wp_query ) { /*my solution */ if($_GET['post_type'] != 'attorney' ) return $search; /*my solution*/ //please copy the rest of the code from the link...
Search Post Title Only
wordpress
I wrote two plugins that utilize the registration_errors filter: <code> add_filter( 'registration_errors', 'process_payment', 10, 3 ); add_filter( 'registration_errors', 'add_user_to_SF', 10, 3 ); </code> When <code> add_user_to_SF </code> returns errors, the <code> process_payment </code> function runs successfully (I...
Identifying errors via error code Run <code> add_user_to_SF </code> with an earlier priority, to make it execute first <code> add_filter( 'registration_errors', 'add_user_to_SF', 9, 3 );` </code> Let's assume you have two possible errors in your <code> add_user_to_SF </code> : <code> function add_user_to_SF( $errors, $...
Two functions utilizing registration_errors filter
wordpress
I want to organize themes like: <code> wp-content/themes/themeshop/theme1 </code> <code> wp-content/themes/themeshop/theme2 </code> <code> wp-content/themes/themeshop/theme3 </code> Now from my understanding, this organization works perfectly at the folder level. I dropped themes in subdirectories and everything seems ...
Updated plugin version available at GitHub. I first saw your Question at [wp-hackers] list , and, after implementing the solution, was about to publish a Q&amp;A for that. Well, it's already here, and has a bounty put on it :) As Daniel Bachhuber points out in the thread: WordPress.com puts themes inside of subdirector...
Categorising themes by folders in backend
wordpress
I have following code in my <code> .php </code> file: <code> $my_pages = wp_list_pages("title_li=&amp;child_of=".$my_id."&amp;echo=0"); </code> Then I create an <code> &lt;ul&gt; </code> <code> &lt;ul&gt; &lt;?php echo $my_pages; ?&gt; &lt;/ul&gt; </code> Problem is, that I would like to list a title in <code> &lt;h2&g...
No, it is not possible. you will want to use <code> WP_Query() </code> Here is the Codex Article on that. Example: <code> &lt;?php // Query All Pages $my_query = new WP_Query( 'post_type=page' ); // The Loop while ( $my_query-&gt;have_posts() ) : $my_query-&gt;the_post(); echo '&lt;h2&gt;' . get_the_title() . '&lt;/h2&...
Custom wp_list_pages() function
wordpress
I have the following <code> $mydate = "26 January, 2012, 5:05 AM"; </code> I want to format this date properly so I can insert it into a post_date. Is there a simple way to do it? <code> $post_ information = array ( //other data is also inserted 'post_date' =&gt; $mydate; ); </code>
That format is almost readable by <code> strtotime </code> . Remove the commas and it will convert. <code> $t = '27 January, 2012, 5:05 AM'; $t = str_replace(',','',$t); $t = strtotime($t); echo date('Y-m-d H:i:s',$t); </code>
Format Date for Manual Insertion into post
wordpress
I'm trying to get the line of codes below to display it's content on "web-design-portfolio" and "web-design-portfolio-2" but it ends up messing up every other pages on my website and displays the "Ul" element on them. Any ideas what the problem could be. <code> &lt;?php is_page(array('web-design-portfolio','web-design-...
<code> is_page() </code> returns <code> boolean true </code> or <code> boolean false </code> . The way you've called it looks like it would have no effect. Try this: <code> if ( is_page( array( 'web-design-portfolio', 'web-design-portfolio-2' ) ) ) { ?&gt; &lt;!-- All your display code code --&gt; &lt;?php } // ends th...
Conditional display faults
wordpress
Af first, I'm not a programmer. In Woocommerce I need to display both product prices, including tax and excluding tax. Code in price.php <code> &lt;?php if ( $price_html = $product-&gt;get_price_html() ) : ?&gt; </code> is showing default price we entered as product price (this price is excluding tax). I have a problem...
Try: <code> &lt;?php echo woocommerce_price($product-&gt;get_price_including_tax()); ?&gt; </code>
Woocommerce price including tax with formatting from options
wordpress
I know it seems to be a strange ask here but hear me out. I have a client who has several subdomains for different countries, such as us.example.com and uk.example.com. I want to change one or two pages of a wordpress website when there is a certain subdomain entered. Before anyone asks I have mentioned having the diff...
Just check the current host: <code> add_filter( 'the_content', 'domain_dependent_content' ); function domain_dependent_content( $content ) { // get_the_ID() will return the current post ID if you need // more information about the current page. if ( 'page' !== get_post_type() ) return $content; if ( 'au.example.com' ==...
Different Subdomain changes page content
wordpress
I´m trying to highlight (using css), the child and parent categories in use in the selected post. So I´ve found this plugin "Kahi's Highlight Used Categories". Plugin´s website: http://kahi.cz/wordpress/highlight-used-categories-plugin/ What it does... It adds a 'used-cat' class and 'used-cat-parent' class to stylize, ...
Use the category ID: <code> class KHUC { function wp_list_categories ($text) { global $post; if (is_singular()) { $categories = wp_get_post_categories($post-&gt;ID); foreach ($categories as $category_id) { $category = get_category($category_id); $category_parent = get_category($category-&gt;category_parent); $text = pr...
Editing "Kahi's Highlight Used Categories" plugin code - highlighting parent and child category in post page
wordpress
Is there an equivalent to <code> INSERT IGNORE </code> in the <code> wpdb </code> class? As I'm fetching and inserting a twitter feed and the field in which I store the tweet ID is keyed <code> UNIQUE </code> , I am aware that duplicates are going to occur and do not need Wordpress informing me of them in my PHP error ...
To answer the question directly, there is <code> $wpdb-&gt;update </code> but nothing that will strictly duplicate <code> INSERT IGNORE </code> that I know of. If <code> $wpdb-&gt;update </code> , does not work I am fairly sure that you will need to write your own query and use <code> $wpdb-&gt;query </code> and <code>...
$wpdb-> insert Database Error Duplicate Entry Error Logging
wordpress
I want to count author posts and store this number for later use even if some of the posts have been deleted in the meantime. <code> $rows = $wpdb-&gt;get_results( $wpdb-&gt;prepare( "SELECT post_status, COUNT(ID) as count FROM $wpdb-&gt;posts WHERE post_author = %d AND post_type = 'post_type' GROUP BY post_status", $c...
You can use <code> update_user_meta() </code> to add information to a user's meta fields, and <code> count_user_posts() </code> to get an initial count. So, for instance: <code> &lt;?php add_action( 'new_to_publish', 'wpse96358_author_count' ); add_action( 'draft_to_publish', 'wps396358_author_count' ); function wpse96...
Count user posts and store the number for later use
wordpress
I'm using wp mail to send an html email. But there's quite a lot of html code in the email, so rather than including all the code in my wp mail function, is it possible to have the code in a separate template and just include this template in the function? Here is what I have <code> &lt;?php if ( isset( $_POST['submitt...
Per my comment to your question, I believe the problem is that <code> include </code> ing files, whether directly or using <code> get_template_part </code> isn't likely to give you a string to pass to <code> $body </code> and that is going to cause errors in the code, or at the very least unespected behavior. I would a...
Include HTML template file in wp mail
wordpress
I am trying to change the look of my searchform. It basically needs to have two text fields. I want this to be in form of a plugin, which anyone can activate. SO obviously I do not have any control over <code> searchform.php </code> . And I also read that if searchform.php is present, then echo parameter is ignored ( <...
There is no safe way to catch the content of a <code> searchform.php </code> in this case. You could run output buffering on the complete page, but then you would probably run into stackexchange-url ("conflicts with other plugins doing the same"). Alternative solution: Add a widget to your plugin that offers another se...
Using ob_get_content to get_search_form puts into infinite loop
wordpress
This is probably a silly question, but I'm new to wordpress development so easily confused at the moment. Code: <code> array( 'label' => 'Repeatable', 'desc' => 'A description for the field.', 'id' => $prefix.'repeatable', 'type' => 'repeatable' ) </code> My Q: Is <code> 'repeatable' </code> a standard feature of wordp...
WordPress has no real form API, you have to create almost all form elements from scratch. <code> 'type' =&gt; 'repeatable' </code> is part of an external library. Google lead me to this article: Reusable Custom Meta Boxes Part 3: Extra Fields – maybe a starting point for your research?
Is 'repeatable' a field type for meta boxes?
wordpress
I observed the inside the <code> wp_head </code> function in the source links of every <code> .css </code> , <code> .js </code> files a <code> ?ver=1 </code> ( or other number based on the file's/library version ) is added. How can I overwrite them, to remove them? This issue I think is causing problems on the cache ma...
You can hook into <code> style_loader_src </code> and <code> script_loader_src </code> and run <code> remove_query_arg( 'ver', $url ) </code> on the URL: <code> &lt;?php /* Plugin Name: Remove version parameter for scripts and styles */ add_filter( 'style_loader_src', 't5_remove_version' ); add_filter( 'script_loader_s...
How to remove file versions from the file source links in wp_head?
wordpress
I use the following code for getting the authors of in my multi-author blog and order them by their post count. I want to order them by the date of their last post <code> $authors = get_users('role=author&amp;orderby=post_count&amp;order=DESC'); </code>
Put this in your <code> functions.php </code> : <code> function get_users_ordered_by_post_date($args = '') { // Prepare arguments if (is_string($args) &amp;&amp; '' !== $args) parse_str($args, $args); $asc = (isset($args['order']) &amp;&amp; 'ASC' === strtoupper($args['order'])); unset($args['orderby']); unset($args['o...
Order the users by the date of their latest post
wordpress
Using the following code stackexchange-url ("from this post") I thought I had found the answer to my problems of showing authors that have posted in the last 6 months. Unfortunately the way the function checks the date it only seems to block some months and doesn't take in to consideration previous years as it is showi...
You might want to use something like this: <code> if (strtotime('-6 months', time()) &gt;= strtotime($posts[0]-&gt;post_date)) continue; </code> When using <code> strtotime </code> , you actually can calculate in words , (e.g., <code> +1 month </code> , <code> -3 hours </code> ).
Author List page: Exclude based on last post date not working correctly
wordpress
How do I remove this? Preferaly would like to do an action hook inside functions.php to remove this. I don't want the editor to see/edit when they published the article. Thank you for your help.
You could hide it for non-admins with CSS : <code> function hide_curtime_wpse_96106() { if(get_post_type() === "post"){ if(!current_user_can('manage_options')){ // only for non-admins echo "&lt;style&gt;.misc-pub-section.curtime {display:none !important;} &lt;/style&gt;"; } } } </code> Before: After:
Remove "Published On" inside wp-admin
wordpress
I have started a very simple wordpress blog for a hockey pool I run. The site is located at: http://thekeeperpool.wordpress.com/ I manage the actual stats counting and player movement using a local application I made in c#. I have written some logic to output the HTML needed for the body of each persons team page. (e.g...
Use the XML-RPC API to post to your blog. Windows Live Writer and other apps are using that too. I am not very familiar with that API, so I have no good examples. But you should find enough with the keyword. There are also many plugins with sample code.
How can I send edits to my blog programmaticly?
wordpress
I have several post formats and I want to use <code> add_filter </code> selectively, applying the filter to some of the post formats but not all. When I do this in my <code> functions.php </code> file it affect all the post formats. It also affects all my custom post types which I want to avoid. <code> function test_fi...
Use <code> get_post_format() </code> : <code> function test_filter($content) { $format = get_post_format(); if ( ! $format ) return $content; if ( 'audio' === $format ) // do something with audio if ( 'aside' === $format ) // do something with aside return "$content &lt;hr&gt;post format: $format"; } </code> Since <cod...
How can I add a filter to a particular post format?
wordpress
I am using the code in a page below to let users delete their posts from the front in. I have wp-admin totally blocked off to site users. What i want to do is when they click the delete button the post actually goes into draft or pending mode so there is still a record of the post but the front end cant view it. <code>...
Simply replace <code> wp_delete_post( get_query_var( 'postid1'), true ); </code> with <code> wp_update_post( array( 'ID' =&gt; get_query_var( 'postid1' ), 'post_status' =&gt; 'draft' ) ); </code> That is assuming that the rest of your logic does already work.
Change Post Status From Front End
wordpress
This is my situation. I have two plugins, one plugin will read a remote XML file and downloads content then it calls a function on another plugin to do the actual importing of posts to the WordPress database. Now here is the problem, the second problem inserts posts using wp_insert_post method and this is a multisite i...
The solution that I've found is to add this line just before doing the import: <code> if (function_exists('kses_remove_filters')) { kses_remove_filters(); } </code> That will disable the kses filters responsible for stripping HTML tag inside the post_content. I have successfully added this to the first plugin. Once thi...
how to use force_filtered_html_on_import in add_filter?
wordpress
I'm currently using the code below to list sticky posts on my index.php. However, when no sticky posts are present, its loading the latest posts (up to the number specified in "settings > reading > blog posts show at most _ posts". How can I alter the script so that if there are no sticky posts, it exits out of the whi...
That is because <code> get_option </code> will return an empty array if there are no sticky posts and the query will default to everything. <code> $sticky = get_option('sticky_posts'); if (!empty($sticky)) { $args['post__in'] = $sticky; $qry = new WP_Query(array('post__in' =&gt; $sticky)); if ($qry-&gt;have_posts()) : ...
Force index.php have_posts() loop to exit if no sticky posts found
wordpress
How do I enqueue a .css file before style.css is loaded? Or make the default style.css dependant on another .css file? I'm trying to load a .css reset, which style.css would overwrite. Here's what I have: <code> add_action('wp_enqueue_scripts', 'load_css_files'); function load_css_files() { wp_register_style( 'normaliz...
Enqueue the <code> style.css </code> too, and set <code> normalize </code> as dependency: <code> function load_css_files() { wp_register_style( 'normalize', get_template_directory_uri() . '/css/normalize.css'); wp_register_style( 'theme_name', get_stylesheet_uri(), array( 'normalize' )); wp_enqueue_style( 'theme_name' ...
How to enqueue style before style.css
wordpress
I'm trying to set multiple images (image A,B and C) from one folder (folder X) at random into the database as a default featured image when there's none one set. So on the main page I have all posts with different featured images from folder X. After clicking on read later the featured image needs to be the same as the...
Thanks to @Noob Theory for helping me out on the first part. Solution: Upload 'default headers' to 'media' and check their ID's. Use <code> array_rand </code> to randomize the ID's et voila, your done. <code> &lt;? function autoset_featured() { $media_array = array( '1611', '1612', '1613', ); $media = $media_array[arra...
If no featured image, add one of the default images into DB
wordpress
I am trying to add Facebox (a lightbox type image viewer) to my WordPress theme at but presently the images are not loading. I have tried hard coding this and also using the Facebox WP Gallery plugin with no success with either method yet. I currently have it hard coded using this code in <code> header.php </code> and ...
// UPDATE This should work (it does for me, at least): in your theme's folder, create the subfolder <code> facebox </code> put only the content of the <code> src </code> folder into your <code> facebox </code> folder (i.e., closelabel.png, facebox.css, facebox.js, loading.gif). put the following in your <code> function...
How to use Facebox in WordPress theme?
wordpress
On the user-profile page of my site I want to allow admin role users to be able to edit specific user-meta fields of subscriber role users. How can I distinguish between the two user IDs. The current logged in user is the admin user <code> get_current_user(); // returns the admin role user id </code> but I need to be a...
On the "profile page", i.e. <code> user-edit.php </code> in the admin back-end, the user ID of the profile currently being edited lives in the <code> $user_id </code> global. Hence: <code> global $user_id; update_user_meta( $user_id, 'key', 'value' ); </code> is the essence of what you are looking for. Whether the curr...
Distinguish profile user and admin user IDs / get ID of user being edited
wordpress
I've registered a new content type with following - <code> register_post_type('news', array( 'labels' =&gt; array( 'name' =&gt; __( 'News'), 'singular_name' =&gt; __( 'News'), 'add_new' =&gt; _x( 'Add New News', 'News'), 'add_new_item' =&gt; __( 'Add New News'), 'edit_item' =&gt; __( 'Edit News'), 'new_item' =&gt; __( ...
Just added <code> 'all_items' =&gt; __( '' ), </code> in labels array. Replace your code with below code <code> register_post_type('news', array( 'labels' =&gt; array( 'name' =&gt; __( 'News'), 'singular_name' =&gt; __( 'News'), 'add_new' =&gt; _x( 'Add New News', 'News'), 'add_new_item' =&gt; __( 'Add New News'), 'edi...
wordpress custom post type remove duplicate menu item
wordpress
I am developing a theme which has a different method of adding in content and so, the default install of Wordpress won't show any content because of this. I was wondering if it is possible to automatically import an XML file via means of an internal function and or hooks after the theme has been activated? User install...
Your question is a bit specific if you "only" want to automatically import some posts/pages. There are other ways to do this then using a XML export file. If you have text-only posts, then you should use LOAD DATA INFILE. At first you have to export your posts. <code> global $wpdb, $wp_filesystem; $tables = array( 'pos...
Import Wordpress XML File from Within Functions.php
wordpress
How can I disable plugin upload and installation via Wordpress Admin? Should still be able to activate/deactivate plugins in admin.
There is a constant you can define in <code> wp-config.php </code> to do this. It will also disable the theme edit, however. <code> &lt;?php // somewhere in wp-config.php define('DISALLOW_FILE_MODS', true); </code> That will remove the plugin and theme file editor (which are a terrible idea anyway) and remove the abili...
Disable /wp-admin/plugin-install.php
wordpress
Is it possible to filter the output of either the content or excerpt so that I only get the the shortcode output and so that if a user enters more than the shortcode the rest of the content for that page would be stripped.
<code> function shortcode_only_wpse_96114($content) { $regex = get_shortcode_regex(); preg_match_all('/'.$regex.'/',$content,$matches); if (!empty($matches[0])) { $content = do_shortcode(implode(' ',$matches[0])); } return $content; } add_filter('the_content','shortcode_only_wpse_96114',1); </code> That should check fo...
Filter everything from content except output of a shortcode
wordpress
I am getting the following notice from Google PageSpeed: <code> Avoid landing page redirects To speed up page load times for visitors of your site, remove as many landing page redirections as possible, and make any required redirections cacheable if possible. http://site.com/blog is a non-cacheable redirect to http://s...
One of the most wasteful redirects happens frequently and web developers are generally not aware of it. It occurs when a trailing slash (/) is missing from a URL that should otherwise have one. For example, going to http://astrology.yahoo.com/astrology results in a 301 response containing a redirect to http://astrology...
Google PageSpeed: Avoid landing page redirects?
wordpress
I am currently working on adding options to the theme customizer. For the last two hours I have been trying to get the live preview working and I am trying figure out why my theme isn't loading the <code> theme-customizer.js </code> file needed for the live preview. All of the options I have added to the theme-customiz...
i think your script is loaded correctly, same function is used in twentytwelve ( but your script is inside the iframe) but i can be wrong (dont know excactly how your theme is construct, maybe it's a path related issue with multiple include) to see the change with no refresh you have to you use the 'transport' argument...
Theme Customizer not loading JS for live preview
wordpress
I've tried plugins, read through stack and spent hours on this, and I just can't seem to find a way to achieve what I want. I can achieve the following permalink structure: <code> custom-post-type/taxonomy-term/post-title </code> for example, <code> our-work/interactive/some-project-title </code> which also allows <cod...
Replace your code with the following. I have made some changes to the <code> post_type_link </code> filter's callback function. <code> function my_custom_post_work() { $labels = array( 'name' =&gt; _x( 'Work', 'post type general name' ), 'singular_name' =&gt; _x( 'Work', 'post type singular name' ), 'add_new' =&gt; _x(...
Custom Post Type / Taxonomy Slug / Post Title with post type archive
wordpress
I'd like to make the back-end of the SlideDeck 2 plugin visible for admin users only. Also, I'd like to remove that "Insert SlideDeck" button from the editor. How can I do this?
Put the following in your <code> functions.php </code> : <code> if (is_admin() &amp;&amp; ! current_user_can('install_plugins')) { add_action('admin_init', 'remove_slidedeck_menu_page'); add_action('admin_footer', 'remove_slidedeck_media_button'); } // remove the menu page function remove_slidedeck_menu_page() { remove...
SlideDeck 2, make back-end visible for admins only
wordpress
I am developing a theme and I have called jquery along with other JS files from a theme-enqueue.php file. For some reason only the Jquery file that is hosted on googles servers is adding the theme URL into the URL path so it is not loading it and causing other JS files to not load properly. The hook is done properly an...
If you register a script with <code> wp_register_script() </code> it is not neccessary to pass all the options in <code> wp_enqueue_script() </code> again. You can register the script in a central place and use the enqueueing it in diffenrent files. <code> functions.php wp_register_script( 'theme_script', 'path/to/scri...
Theme not calling Jquery properly
wordpress
When I upload an image through the admin interface, the image is only saved at full-size. The other sizes are configured to their default values in Settings > Media. The automatic resized versions are not being generated. I have a feeling this is due to not having a specific PHP extension installed/enabled, but I don't...
The solution turned out to be avoiding php-gd altogether as I couldn't get it installed. Instead, I installed the ImageMagick Engine WordPress plugin as well as ImageMagick on the server. Then I regenerated image sizes using the plugin to create the additional sizes for images I had already uploaded. I posted the solut...
Additional image sizes are not being generated
wordpress
When inserting a gallery it adds the following shortcode: <code> [gallery columns="6" ids="18,150,146,23,147,17,21,20,22"] </code> I would like it to automatically add link="file" as the last attribute, whenever a shortcode is added. Like so: <code> [gallery columns="6" ids="18,150,146,23,147,17,21,20,22" link="file"] ...
You can hijack the shortcode handler and set the attribute to a value of your choice. Then call the native callback for this shortcode. <code> add_shortcode( 'gallery', 'file_gallery_shortcode' ); function file_gallery_shortcode( $atts ) { $atts['link'] = 'file'; return gallery_shortcode( $atts ); } </code>
Automatically add this attribute to the gallery shortcode
wordpress
It's pretty easy to query posts from one category but what if I need also one single post from another category? <code> $query = new WP_Query( 'cat=4' ); </code> I'm looking for something like this: <code> $query = new WP_Query( array( 'cat' =&gt; 4, 'post__in' =&gt; array( 20 ) ) ); </code> But the above code will not...
I don't see a way to do this with <code> WP_Query </code> alone. However... <code> function posts_where_add_post_wpse_96030($where) { global $wpdb; return $where." OR {$wpdb-&gt;posts}.ID = 1"; } add_filter('posts_where','posts_where_add_post_wpse_96030'); $query = new WP_Query( 'cat=9' ); </code> That will alter the q...
Query "Category A" + 1 post from "Category B" - how?
wordpress
(I've posted this on the normal stack exchange, but it was suggested that I put it here too. Glad to know this place exists... :)) So, I've been all over the internet trying to figure out what is going on with a couple of sites that I have, and I think I've finally been able to track it down... BUT I want to first make...
Removing the <code> hierarchical </code> parameter from the <code> register_post_type </code> function call did the trick, as per vancoder's suggestion. On the back end, looking at what the hierarchical option does (set the new post type to behave like the <code> page </code> post type) tells me that it probably should...
Wordpress Custom Post Type Admin Page really slow
wordpress
I am trying to programmatically set the 'page_on_front' option with the id value retrieved from the get_page_by_title command... <code> $homepage = get_page_by_title( 'Front Page' ); update_option('page_on_front', $homepage); update_option('show_on_front', 'page'); </code> This isn't working, can anyone help?
<code> get_page_by_title() </code> returns an object. Use <code> $homepage-&gt;ID </code> . You should also check if you really got a usable return value: <code> $homepage = get_page_by_title( 'Front Page' ); if ( $homepage ) { update_option( 'page_on_front', $homepage-&gt;ID ); update_option( 'show_on_front', 'page' )...
Programmatically set page_on_front
wordpress
I'm working on a plugin that allows the user to create "page/post types", customize the type style, then tag a page/post with that type. All of this works. My problem is this plugin also needs to allow them to attach widgets to said type. I have no way of knowing how many "types" there are at any time. The plugin works...
I ended up just creating a sidebar and any item that was placed there, a dropdown box was added to assign it a special location.
I need some direction on how to have a sidebar based on meta rather than page
wordpress