Hot answers tagged

26

Since WordPress 3.5 this option (XML-RPC) is enabled by default, and the ability to turn it off from WordPress dashboard is gone. Add this code snippet for use in functions.php: // Disable use XML-RPC add_filter( 'xmlrpc_enabled', '__return_false' ); // Disable X-Pingback to header add_filter( 'wp_headers', 'disable_x_pingback' ); function ...


25

The answer by shea is not ideal as in many cases: You don't want to strip everything from <br>, <p> etc. You want it as a default behavior for your WP visual composer which the above code will delete In many cases it is considered as "hacking the core" as this is changing the default core behavior of WP - for example such a thing will not pass ...


22

<?php // would echo post 7's content up until the <!--more--> tag $post_7 = get_post(7); $excerpt = $post_7->post_excerpt; echo $excerpt; // would get post 12's entire content after which you // can manipulate it with your own trimming preferences $post_12 = get_post(12); $trim_me = $post_12->post_content; my_trim_function( $trim_me ); ?&...


20

Here you go ! <?php $my_id = 5369; $post_id_5369 = get_post($my_id); $content = $post_id_5369->post_content; $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); echo $content; ?>


13

The wpautop() function adds <p> and <br> tags to your content in order to preserve line breaks. If you would rather add these tags yourself, then you can remove the filters which apply this function to the post content: remove_filter( 'the_content', 'wpautop' ); remove_filter( 'the_excerpt', 'wpautop' ); If you would like to keep the automatic ...


11

The content is a property of the post object, not of the query object. Use $post or get_post() instead: if( '' !== get_post()->post_content ) { // do something }


9

Not exactly sure what you are trying to accomplish, but it looks like you are trying to prepend something to the beginning of the_content. Try this: add_filter('the_content', 'se24265_my_function'); function se24265_my_function( $content ) { $write = 'hello world'; $new_content = $write . $content; return $new_content; } Most filters will ...


9

WordPress has a handy function called post_exists() which allows you to find an existing post by its title, content, and/or date. It returns the post ID on success or 0 otherwise. In your case, you can use $post_id = post_exists( '', '{"member_id":33}' ) to find the post you're looking for. Note: That function doesn't check the post type so you'd need to ...


8

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 WordPress installation's root directory. public_html/...


8

Caution: very mac/linux/unix centric thoughts ahead. Includes a lot of command line fu. Put All the Code Under Version Control I like git. Mark Jaquith has some good suggestions on keeping an entire site under version control using git and submodules for the WordPress core. You could also put plugins in as git submodules. The developer end of the team ...


8

My way to do this (see update below): function addParagraphs($content) { // you can add as many as you want: $additions = array( '<p>After 1st paragraph</p>', '<p>After 2nd paragraph</p>' ); $content = get_the_content(); $output = ''; // define variable to avoid PHP warnings $parts = explode(...


8

Wordpress automatically ads the <p> tags to the content. So it shows up while loading the content. This is with the filter wpautop. So we will remove this filter for the image post type only. You can manage this by adding the following code in functions.php file. // Add the filter to manage the p tags add_filter( 'the_content', '...


8

How to trigger an oembed cache regeneration The default cache time is 24 hours and we can adjust it with the oembed_ttl filter. But as you've noticed, expired cache is not enough to trigger a cache regeneration. The reason is this line in the WP_Embed class: if ( $this->usecache || $cached_recently ) { so to trigger a regeneration, we need both ...


7

First off: The ID of a post or page is always an integer. "about" is either your about page's title, slug or both. Including the following in your "homepage's" page template or in the sidebar combined with conditional tag(s) will display the about page's content: <?php // query for the about page $your_query = new WP_Query( 'pagename=about' ); ...


7

Typically you use widgets or custom post types but in reality these solutions can be unfriendly to clients. WordPress still revolves around the idea of a post based loop so doing traditional "content blocks" that you might find in other frameworks can be difficult. Fortunately there are plugins that are pretty good in this area. I recommend checking out ...


7

You can use output buffering to accomplish this. Add a high priority hook directly before the template is rendered: add_action('template_redirect', 'foo_buffer_go', 0); function foo_buffer_go(){ ob_start('foo_buffer_callback'); } Add a shutdown hook with an extremely low priority. add_action('shutdown', 'foo_buffer_stop', 1000); function ...


7

I always use the Theme Unit Test that Theme Reviewers use to evaluate themes for the Repo. It's got pretty much everything you need to style/worry about. And if I need to create batch content in a different way, then I use WP Dummy Content


7

Yep, wp_trim_words(): <?php $trimmed = wp_trim_words( $text, $num_words = 55, $more = null ); ?> Or in your case: <?php echo apply_filters( 'the_content', wp_trim_words( strip_tags( $post->post_content ), 55 ) ); ?>


7

First set the post type to display on main feed page i.e. /feed using pre_get_posts hook $q->set('post_type', array('post', 'page')); On individual page WordPress shows comment feed then set it to false and display page content in feed. $q->is_comment_feed = false; In feed template WordPress calls the_excerpt_rss() which calls get_the_excerpt() so ...


6

I ended up using userabuser's answer with a small modification, because global $post doesn't seem to exist on init. You can instead just query for post in querystring, like so: function remove_editor() { if (isset($_GET['post'])) { $id = $_GET['post']; $template = get_post_meta($id, '_wp_page_template', true); if($template == '...


6

You already got something like this built in: Revisions. // Define the nr of saved revisions in your wp-config.php define( 'WP_POST_REVISIONS', 30 ); You can simply grab them by calling get_posts() with a post_type of revision. To show the difference between two revisions simply use wp_text_diff(). // Example $revisions = get_posts( array( 'post_type'...


6

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', '...


6

You can use the_content with an high prioriety (lower number). add_filter( 'the_content', function( $content ) { return 'Hello World '.$content; }, 0); You can even use negative priority: add_filter( 'the_content', function( $content ) { return 'Hello World '.$content; }, -10); Note that this will apply everytime 'the_content' is used, no matter the ...


6

In your dashboard go to settings/permalinks. Hit save. You should be able to see your cpts now.


5

You could use a Git hook and post per XML-RPC to WordPress. A Git hook can be any executable file, even PHP. Another option – on GitHub – is to use the email hook: Go to https://github.com/username/projectname/admin/hooks, select Email and send an email to the blog. Enable the Post per email feature.


5

If we look at the source of wp_insert_attachment() we find the hooks edit_attachment and add_attachment. In your case we could use the add_attachment hook. The callback takes the attachment's ID as a parameter. By looking at the database table wp_posts we see that the description is saved as post_content and the caption as post_excerpt: Then you could try ...


5

You have to define WP_CONTENT_DIR and WP_CONTENT_URL: const WP_CONTENT_DIR = '/path/to/new/directory'; const WP_CONTENT_URL = 'http://content.wp'; The new path must be accessible for read and write operation from the WordPress core directory. You might need a helper function to add the new directory path to the open_basedir list: /** * Add a new ...


5

The internal implementation details of that feature are of questionable sanity. If you take a look at said featured-content.php template you would see that it get posts from twentyfourteen_get_featured_posts() however the only thing that function has is twentyfourteen_get_featured_posts filter from quick look at which in peculiar fashion nothing is actually ...


5

You can disable the visual editor entirely in your profile settings. If you need to disable it on a per page basis, take a look at this answer. Using text mode may not solve the empty paragraph problem, the wpautop filter is applied to the content regardless of how the content is edited. You can remove the filter, but then you'll have to manually break and ...


5

No need to reinvent the wheel - put your editor support back and tweak the settings: function wpse_199918_wp_editor_settings( $settings, $editor_id ) { if ( $editor_id === 'content' && get_current_screen()->post_type === 'custom_post_type' ) { $settings['tinymce'] = false; $settings['quicktags'] = false; $settings['...


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