Search content for shortcodes and get parameters

This is working for me $shortcode=”book”; $pattern = get_shortcode_regex(); // if shortcode ‘book’ exists if ( preg_match_all( “https://wordpress.stackexchange.com/”. $pattern .’/s’, $post->post_content, $matches ) && array_key_exists( 2, $matches ) && in_array( $shortcode, $matches[2] ) ) { $shortcode_atts = array_keys($matches[2], $shortcode); // if shortcode has attributes if (!empty($shortcode_atts)) { foreach($shortcode_atts as $att) { preg_match(‘/id=”(\d+)”https://wordpress.stackexchange.com/”, $matches[3][$att], $book_id); // … Read more

What is the best / efficient way to get WordPress content by post id and why?

The methods you offer for comparison are pretty much the same, with minor API differences and whether the_content filters are applied. Within the loop get_the_content() should typically be used, which properly handles split into pages and so on. To retrieve raw content get_post_field() is generally suitable, but any further processing (such as the_content filters) heavily … Read more

What is the best way to include a widget in a Page?

This plugin might be the easy way. http://wordpress.org/extend/plugins/add-widgets-to-page/ But for a scratch method… Look into Theme Twenty-Ten’s functions.php file and find where the dynamic sidebars are registered. It looks like this: <?php function twentyten_widgets_init() { // Area 1, located at the top of the sidebar. register_sidebar( array( ‘name’ => __( ‘Primary Widget Area’, ‘twentyten’ ), … Read more

Change Output for Images in Content

One way is to do this dynamically: function do_the_replacements($matches){ // $matches[0] = full string // $matches[1] = link attributes // $matches[2] = link contentes (the image) // change ‘someclass’ here… if(strpos($matches[2], ‘someclass’) !== false){ return ‘ <div class=”featured-img”> <a ‘.$matches[1].’>’.$matches[2].'</a> <div class=”corner-nw”></div> <div class=”corner-ne”></div> <div class=”corner-sw”></div> <div class=”corner-se”></div> </div> ‘; } // no matches, leave … Read more

How do I make certain areas editable?

These links should help you: http://codex.wordpress.org/The_Loop http://codex.wordpress.org/Function_Reference/wp_get_nav_menu_items with this two techniks you can give your client the ability to change the content and the navigation. For these you have to edit your theme and insert the snippets on the placese you want to output your contents…. For the footer you can use a custom page … Read more

Multiple content areas per page

This sounds to me like a perfect use of Advanced Custom Fields “flexible content” feature to me. Flexible content fields allow you to define multiple layouts, and then add them to a page or post one by one, in any order or combination you need. Each layout can be a combination of text fields, images, … Read more

Multiple areas of dynamic content in a page

The example you gave has a listing of three pages and four posts (which are dated). The same can be achieved by one of the following: two different Custom Post Types, one per block, e. g. post_type=”products” and post_type=”projects”; children of two another pages, e. g. children of “Products” in one block and children of … Read more

How can you make sure authors’ posts are longer than 250 words?

Prevent authors from publishing too short content: Here’s one idea using a custom post status, for example short: /** * Register a custom ‘short’ post status * * @see http://wordpress.stackexchange.com/a/159044/26350 */ function wpse_short_post_status() { register_post_status( ‘short’, array( ‘label’ => _x( ‘Short’, ‘post’ ), ‘public’ => false, ‘exclude_from_search’ => true, ‘show_in_admin_all_list’ => true, ‘show_in_admin_status_list’ => true, … Read more

Host wp-content on other domain, much like a CDN

In WordPress Dashboard > Settings > Media and fill the field “Full URL path to files” with your other domain. See the screenshot below: EDIT: I thought it would be obvious, but it isn’t. Here’s what you exactly need to do: You should map your domain to point to: public_html directory, IF it’s also your … Read more