[custom plugin]Can't get pagename
-
Good day dear WordPress community,
I hope that this is the right category, since I mostly read about existing plugins having troubles working. However, I am creating my own plugin with above basic php knowledge.
I am attempting to get the pagename, so that I can edit the page’s content when the url says /producten/ (Dutch for products)
However, I have 2 problems
The first being: the code I looked up on the internet, stated as resolved, doesn’t work. Here’s my piece of code to check if the code actually works:
global $post; $pagename = get_post( $post )->post_name; ?> <script type="text/javascript"> <?php echo 'alert("Paginanaam: ' . $pagename . '")';?> </script>
Here’s what will pop up: imgur
This also brings me to the second problem: I want the content to change as soon as the pagename reaches state
if ($pagename == "producten")
However, I do not know which hook to execute my function for the page to change content:if ($pagename == "producten") { add_action("wp_header","verander_titel"); function verander_titel() { ?> <div class="wrap"> <h3>It worked!</h3> </div> <?php } verander_titel(); }
- The topic ‘[custom plugin]Can't get pagename’ is closed to new replies.