most recent 30 from wordpress.stackexchange.com2026-03-01T06:47:42Zhttps://wordpress.stackexchange.com/feeds/user/131617https://creativecommons.org/licenses/by-sa/4.0/rdfhttps://wordpress.stackexchange.com/q/3781902Justin Breenhttps://wordpress.stackexchange.com/users/1316172020-11-14T23:29:14Z2025-04-16T06:27:22Z
<p>How do I add custom fields to a specific menu?</p>
<p>For example, I have menu "Primary" with ID 13. How do I run the <code>wp_nav_menu_item_custom_fields</code> hook only if ID matches the currently selected menu?</p>
<p>I tried getting the ID from the <code>$id</code> parameter of the hook, but it always returns 0. I'm trying to check the ID like this:</p>
<pre class="lang-php prettyprint-override"><code>function add_menu_field( $item_id, $item, $depth, $args, $id ) {
var_dump( $id );
}
add_action( 'wp_nav_menu_item_custom_fields', 'add_menu_field', 10, 5 );
</code></pre>
<p>This returns <code>int(0)</code> but my nav menu ID is 13. Am I using this hook incorrectly, or is there another way to get the ID? My goal is to put custom fields on a specific nav by checking the ID.</p>
<p>Thanks for any help!</p>
https://wordpress.stackexchange.com/q/4116090Justin Breenhttps://wordpress.stackexchange.com/users/1316172022-11-27T22:22:37Z2022-12-16T01:50:03Z
<p>I noticed when creating a fresh site block appender button looks cleaner than my other site. This is a fresh site:</p>
<p><a href="https://i.sstatic.net/t46u1.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/t46u1.png" alt="enter image description here" /></a></p>
<p>This is my other site (big rectangle button):</p>
<p><a href="https://i.sstatic.net/Bg0FD.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Bg0FD.png" alt="enter image description here" /></a></p>
<p>I disabled all plugins and switched theme to twenty-twenty to test. Still looks wrong:</p>
<p><a href="https://i.sstatic.net/8SMmO.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/8SMmO.png" alt="enter image description here" /></a></p>
<p>I made sure no plugins are active, no mu-plugins, no additional CSS, and switched to twenty-twenty-three. When I create post, it still looks like the rectangle button. Am I missing something that would make it look like that?</p>
<p>Thanks!</p>
https://wordpress.stackexchange.com/q/4111310Justin Breenhttps://wordpress.stackexchange.com/users/1316172022-11-08T17:45:35Z2022-11-09T14:34:07Z
<p>I made a plugin using default "todo-list" WordPress provides using <code>npx @wordpress/create-block todo-list</code>. Is there a way to convert to work with multiple blocks?</p>
<p>Basically I built "todo-list" as default, then made a new directory <code>blocks/todo-list</code> and moved src/build folders into there. Then edited <code>todo-list.php</code> register_block_type directory from <code>/build</code> to <code>/blocks/todo-list/build</code>. Then updated package.json start/build scripts to:</p>
<pre><code>"build": "wp-scripts build blocks/todo-list/src/index.js --output-path=blocks/todo-list/build",
"start": "wp-scripts start blocks/todo-list/src/index.js --output-path=blocks/todo-list/build"
</code></pre>
<p>The file structure would be:</p>
<pre><code>- blocks
- todo-list
- build
- src
- block-2
- build
- src
- node_modules
- package-lock.json
- package.json
- readme.txt
- todo-list.php
</code></pre>
<p>I did <code>npm run build</code> and don't see Todo List as a block. I didn't add a block-2 yet, but that would be it. Can this structure work?</p>
<p>Edit: Figured it out and answered below.</p>
https://wordpress.stackexchange.com/questions/411131/-/411142#4111420Justin Breenhttps://wordpress.stackexchange.com/users/1316172022-11-09T01:44:25Z2022-11-09T01:44:25Z<p>I edited the start/build scripts in <code>package.json</code> to this and it works.</p>
<pre><code>"build": "wp-scripts build --webpack-src-dir=block/post-type-register/src --output-path=block/post-type-register/build",
"start": "wp-scripts start --webpack-src-dir=block/post-type-register/src --output-path=block/post-type-register/build"
</code></pre>
https://wordpress.stackexchange.com/q/4028650Justin Breenhttps://wordpress.stackexchange.com/users/1316172022-02-18T21:16:15Z2022-02-19T21:19:50Z
<p>I want to add a table after the_content with a hook, but it's adding <code><p></code> tags in certain areas. This is a plugin, I don't want to remove <code><p></code> tags from all the_content, just the table I'm trying to add.</p>
<p>Here's an example, but my table is bigger and inside it's adding p tags in different spots.</p>
<pre class="lang-php prettyprint-override"><code>function addTable( $content ) {
$table = '<table><tbody><tr><td>Example html here</td></tr></tbody></table>';
$content .= $table;
return $content;
}
add_filter( 'the_content', 'addTable', 20 );
</code></pre>
<p>Someone asked this in 2012, no answer but I'm trying to do the same thing:
<a href="https://wordpress.stackexchange.com/questions/74453/adding-a-form-at-the-end-of-the-content">Adding a form at the end of the content</a></p>
<p>I do <strong>not</strong> want to remove <code><p></code> tags from a theme's entire blog post, only the content I am appending. In this case, I'm appending a table.</p>
<p>Is there a way to disable the formatting for only the content I'm appending? Otherwise, how is it possible in WordPress to attach a form or table to a post with hooks without it adding formatting?</p>
https://wordpress.stackexchange.com/questions/302851/-/302853#302853-2Justin Breenhttps://wordpress.stackexchange.com/users/1316172018-05-07T05:05:43Z2018-05-07T05:50:12Z<p>Try wrapping the button in a PHP <code>if</code> statement that checks if the current user has administrator privelages, like this: </p>
<pre><code><?php if ( current_user_can( 'administrator' ) ) : ?>
<a href="#">Your Button</a>
<?php endif; ?>
</code></pre>
<p>This <a href="https://codex.wordpress.org/Function_Reference/current_user_can" rel="nofollow noreferrer">Wordpress Codex link</a> explains how to check for administrator privileges.</p>
<p>Also, for a 1-liner this is the same thing:</p>
<p><code><?php if ( current_user_can( 'administrator' ) ) { echo '<a href="#">Button</a>'; } ?></code></p>
<p><strong>DO NOT USE</strong> <code>is_admin()</code> for this <a href="https://codex.wordpress.org/Function_Reference/is_admin" rel="nofollow noreferrer">as stated here</a>. That function checks if you're in the dashboard, <strong>not</strong> for the privelages you are looking for.</p>
https://wordpress.stackexchange.com/q/3028440Justin Breenhttps://wordpress.stackexchange.com/users/1316172018-05-07T03:24:56Z2018-05-07T04:03:00Z
<p>My Wordpress site goes looking for an archive page if I append a year after the URL.</p>
<p>For example: <code>http:/mysiteurl.com/my-site/2018</code>. If there are posts from this year, it ends up redirecting to <code>index.php</code> for some reason. If there are no posts from that year, it goes to 404 page which is what I want. For example: <code>http:/mysiteurl.com/my-site/2014</code> goes to a 404 page because there are no posts from that year, which is what I want.</p>
<p>My permalink structure is set to <strong>Post name</strong> which is like this <code>http:/mysiteurl.com/my-site/sample-post/</code>. So typing a year after the URL <strong>should</strong> display a 404 page, <strong>not</strong> show me archives.</p>
<p>Why is this happening?</p>
https://wordpress.stackexchange.com/questions/411609/wrong-block-appender-button-showing?cid=601084Justin Breenhttps://wordpress.stackexchange.com/users/1316172022-11-28T12:15:16Z2022-11-28T12:15:16ZBoth are using WordPress v6.1.1https://wordpress.stackexchange.com/questions/411131/create-plugin-with-multiple-blocks?cid=600471Justin Breenhttps://wordpress.stackexchange.com/users/1316172022-11-08T18:31:35Z2022-11-08T18:31:35ZThanks. Is there a way to debug why it's not showing? I pointed register_block_type to new build path, and don't see any console errors, but no block.https://wordpress.stackexchange.com/questions/402865/add-hook-after-content-without-formatting?cid=587915Justin Breenhttps://wordpress.stackexchange.com/users/1316172022-02-19T21:21:44Z2022-02-19T21:21:44Z@TomJNowell Thanks I updated my question. I think I tried 10 already, but I'll try different numbers, not sure if that's it.https://wordpress.stackexchange.com/questions/378190/add-custom-fields-to-specific-menus?cid=548867Justin Breenhttps://wordpress.stackexchange.com/users/1316172020-11-15T00:54:41Z2020-11-15T00:54:41Z@SallyCJ Yes but how can I compare <code>$id</code> if it always returns 0.https://wordpress.stackexchange.com/questions/302851/how-to-disable-edit-link-button-bottom-of-the-page-for-all-users-except-administ/302853?cid=447513#302853Justin Breenhttps://wordpress.stackexchange.com/users/1316172018-05-07T05:21:20Z2018-05-07T05:21:20Z@KrzysiekDróżdż You're right! I updated my answer, and Wordpress Codex link.https://wordpress.stackexchange.com/questions/302844/prevent-archive-urls/302845?cid=447510#302845Justin Breenhttps://wordpress.stackexchange.com/users/1316172018-05-07T04:52:03Z2018-05-07T04:52:03ZThis works! I don't know why it does that when I set my permalink structure to "Post name". I thought if there's no page or post named "2018" then it should show the 404 page. Thanks for the help! (also I have registered some Custom Post Types if that makes a difference but they all have <code>has_archive => false</code>)