most recent 30 from wordpress.stackexchange.com 2026-03-01T06:47:42Z https://wordpress.stackexchange.com/feeds/user/131617 https://creativecommons.org/licenses/by-sa/4.0/rdf https://wordpress.stackexchange.com/q/378190 2 Justin Breen https://wordpress.stackexchange.com/users/131617 2020-11-14T23:29:14Z 2025-04-16T06:27:22Z <p>How do I add custom fields to a specific menu?</p> <p>For example, I have menu &quot;Primary&quot; 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/411609 0 Justin Breen https://wordpress.stackexchange.com/users/131617 2022-11-27T22:22:37Z 2022-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/411131 0 Justin Breen https://wordpress.stackexchange.com/users/131617 2022-11-08T17:45:35Z 2022-11-09T14:34:07Z <p>I made a plugin using default &quot;todo-list&quot; 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 &quot;todo-list&quot; 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>&quot;build&quot;: &quot;wp-scripts build blocks/todo-list/src/index.js --output-path=blocks/todo-list/build&quot;, &quot;start&quot;: &quot;wp-scripts start blocks/todo-list/src/index.js --output-path=blocks/todo-list/build&quot; </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#411142 0 Justin Breen https://wordpress.stackexchange.com/users/131617 2022-11-09T01:44:25Z 2022-11-09T01:44:25Z <p>I edited the start/build scripts in <code>package.json</code> to this and it works.</p> <pre><code>&quot;build&quot;: &quot;wp-scripts build --webpack-src-dir=block/post-type-register/src --output-path=block/post-type-register/build&quot;, &quot;start&quot;: &quot;wp-scripts start --webpack-src-dir=block/post-type-register/src --output-path=block/post-type-register/build&quot; </code></pre> https://wordpress.stackexchange.com/q/402865 0 Justin Breen https://wordpress.stackexchange.com/users/131617 2022-02-18T21:16:15Z 2022-02-19T21:19:50Z <p>I want to add a table after the_content with a hook, but it's adding <code>&lt;p&gt;</code> tags in certain areas. This is a plugin, I don't want to remove <code>&lt;p&gt;</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 = '&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Example html here&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;'; $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>&lt;p&gt;</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 -2 Justin Breen https://wordpress.stackexchange.com/users/131617 2018-05-07T05:05:43Z 2018-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>&lt;?php if ( current_user_can( 'administrator' ) ) : ?&gt; &lt;a href="#"&gt;Your Button&lt;/a&gt; &lt;?php endif; ?&gt; </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>&lt;?php if ( current_user_can( 'administrator' ) ) { echo '&lt;a href="#"&gt;Button&lt;/a&gt;'; } ?&gt;</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/302844 0 Justin Breen https://wordpress.stackexchange.com/users/131617 2018-05-07T03:24:56Z 2018-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=601084 Justin Breen https://wordpress.stackexchange.com/users/131617 2022-11-28T12:15:16Z 2022-11-28T12:15:16Z Both are using WordPress v6.1.1 https://wordpress.stackexchange.com/questions/411131/create-plugin-with-multiple-blocks?cid=600471 Justin Breen https://wordpress.stackexchange.com/users/131617 2022-11-08T18:31:35Z 2022-11-08T18:31:35Z Thanks. Is there a way to debug why it&#39;s not showing? I pointed register_block_type to new build path, and don&#39;t see any console errors, but no block. https://wordpress.stackexchange.com/questions/402865/add-hook-after-content-without-formatting?cid=587915 Justin Breen https://wordpress.stackexchange.com/users/131617 2022-02-19T21:21:44Z 2022-02-19T21:21:44Z @TomJNowell Thanks I updated my question. I think I tried 10 already, but I&#39;ll try different numbers, not sure if that&#39;s it. https://wordpress.stackexchange.com/questions/378190/add-custom-fields-to-specific-menus?cid=548867 Justin Breen https://wordpress.stackexchange.com/users/131617 2020-11-15T00:54:41Z 2020-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#302853 Justin Breen https://wordpress.stackexchange.com/users/131617 2018-05-07T05:21:20Z 2018-05-07T05:21:20Z @KrzysiekDr&#243;żdż You&#39;re right! I updated my answer, and Wordpress Codex link. https://wordpress.stackexchange.com/questions/302844/prevent-archive-urls/302845?cid=447510#302845 Justin Breen https://wordpress.stackexchange.com/users/131617 2018-05-07T04:52:03Z 2018-05-07T04:52:03Z This works! I don&#39;t know why it does that when I set my permalink structure to &quot;Post name&quot;. I thought if there&#39;s no page or post named &quot;2018&quot; 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 =&gt; false</code>)