Tag Info

Hot answers tagged

3

I would do it the other way around: Put the always visible text into a custom field per metabox, and protect the post content with a password. In your theme, always show the custom field, and let WordPress handle the password protection. Sample code for the theme: while ( have_posts() ) { the_post(); if ( post_password_required( $post ) ) { ...


3

Wordpress use an option to store the current active child theme. This option is named 'stylesheet'. Using the filter 'pre_option_{$option_name}' you can change every option getted by WP. So, in your case you should hook the 'pre_option_stylesheet' filter, use some logic to retrieve current season and return the child theme you want. This workflow should be ...


3

I want to suggest you another approach. You can set a meta when you saving a post if its content is less than 140 chars, so then you can simply runs a simple meta query. add_action( 'save_post_post', function( $id, $post ) { if ( $post->post_status !== 'publish' ) return; if ( strlen( $post->post_content <= 140 ) ) { update_post_meta( $id, ...


2

Yes, you could try this - foreach( $create_pages as $new_page ){ $content = "Default ". strtolower($new_page) ." page content"; $add_pages = array( 'post_title' => $new_page, 'post_content' => $content, 'post_status' => 'publish', 'post_type' => 'page' ); $page_id = wp_insert_post($add_pages); } ...


2

Conditional tags mostly derive from and rely on main query. is_page() function calls $wp_query->is_page() method which checks $wp_query->is_page property (set during load) and some more stuff if you asked to check for specific page. So the likely reason for conditional tag not to produce expected return is issue with global $wp_query, for ...


2

On the profile page exists a global variable $profileuser. The member $profileuser->roles is an array of all roles for that user. <?php # -*- coding: utf-8 -*- // Plugin Name: personal_options add_action( 'personal_options', 'print_user_roles'); function print_user_roles() { global $profileuser; print '<pre>$profileuser->roles = ' ...


1

Use just the functions, not the object properties: if ( is_post_type_archive() or is_date() ) There are many conditional functions (returning TRUE or FALSE) for exactly these cases.


1

This really helped me, I combined this with other code I had - I needed to give image links their own class for Magnific Popup, BUT only for my Blog/news section and not custom posts. Hope this helps others: add_filter('the_content', 'my_addlightboxrel'); function my_addlightboxrel($content) { if ( 'craft' == get_post_type() ) return $content; ...


1

To filter the content only when an auto-excerpt is generated you have to chain the hooks: Hook into get_the_excerpt and register a filter for the_content. In the second filter remove both elements and their content before the excerpt can see it. Sample: add_filter( 'get_the_excerpt', 't5_excerpt_clean_up', 1 ); /** * Register handler for ...


1

The dynamic sidebar code you are using uses the page title of the topmost page to name the sidebar. get_the_title finds the title of the page you are on, not the topmost page title. You need a function that tells you the title of the topmost page in a page hierarchy. /** * Get the topmost page title. * * @link ...


1

Since you have specific sidebar on parent pages and default sidebar for subpages, your condition may be ( i am assuming your are in wordpress loop ) check for page, parent page or sub page. check sidebar widget area exist for page if current page is parent page dynamic_sidebar return True, if widget sidebar was found and called. False if not found or ...


1

Here are some ideas: a) Instead of is_category(4,5,6) which checks if a category archive page is being displayed (see here), you can try in_category(4,5,6) or in_category( array(4,5,6) ) that checks if the current post is assigned to any of the specified categories (see here). b) You could also try function woo_post_meta() { if ( ...


1

For custom post types use is_post_type_archive('tips'). Let us know if this works. It should also work with an array is_post_type_archive( array( 'tips', 'cpt', 'another cpt' ) ) I am currently using this function to recognize specific post type archives. See: A Post Type Archive in codex. It would be best if you could specify which cases the menu should ...


1

I can't help but think I am missing something but what seems like the obvious answer is to alter your $create_pages array: $create_pages = array( 'one' => 'content for one', 'two' => 'content for two', 'three' => 'content for three' ); foreach ($create_pages as $title => $content) { $add_pages = array( 'post_title' => ...


1

You need to add your function in the template_redirect hook. You need to first wait for wordpress to finish loading pages before you can add your hook to remove wpautop, otherwise your hook will simply get run over. So your funtion will look like this function pietergoosen_remove_wpautop() { if ( is_page ( 'services' ) ) { remove_filter( 'the_content', ...


1

You can do it like this: <?php $blog_id = get_current_blog_id(); if ( 1 == $blog_id ) { ?> <!-- Your FIRST code block here --> <?php } else { ?> <!-- Your SECOND code block here --> <?php } ?> Here's the whole prettified version of the code you can use (totally UNTESTED, but should work unless there are any silly ...


1

If you're trying to distinguish between your network's "main" site and any others, you can use the conditional tag is_main_site(): if( is_main_site() ) { do_something(); } else { do_something_else(); }


1

try this <?php if ( is_tag( 'Premium' ) ) : ?> <a href="<?php the_permalink(); ?>" class="info">Subscribe</a> <?php else : ?> <a href="<?php the_permalink(); ?>" class="info">Read More</a> <?php endif; ?>


1

Since WP 3.3 you can use wp_enqueue_*() after wp_head, and enqueued scripts and styles (if not already added to the head of the page) would be loaded in the footer. In short just call wp_enqueue_script() / wp_enqueue_style() in your shortcode callback: add_shortcode( 'my_shortcode', 'my_shortcode_callback' ); function my_shortcode_callback(){ ...



Only top voted, non community-wiki answers of a minimum length are eligible