PHP for WordPress Flashcards
(25 cards)
What is PHP in the context of WordPress?
PHP is the server-side scripting language used to build and customize WordPress core, themes, and plugins.
WordPress is written in PHP, making it the backbone for dynamic functionality like rendering posts or handling forms. Freelancers use PHP to create custom themes or plugins for clients, while enterprise architects leverage PHP for scalable integrations and customisations in large WordPress deployments.
What is a PHP variable in WordPress development?
A PHP variable stores data (e.g., strings, numbers) for use in WordPress code, prefixed with $.
Variables like $post or $user_id are used in WordPress to store and manipulate data, such as post titles or user info. Freelancers use variables in custom functions to build dynamic features, while enterprise architects ensure efficient variable management for performance in large systems.
What are PHP arrays in WordPress?
Arrays are data structures that store multiple values, used in WordPress for settings or post data.
Arrays in PHP (e.g., $args = array(‘post_type’ => ‘post’)) are critical for functions like WP_Query. Freelancers use arrays to configure queries or plugin settings, while enterprise architects rely on them for structured data handling in complex applications.
What is the get_template_part()
get_template_part() includes reusable PHP template files in WordPress themes.
This function (e.g., get_template_part(‘template-parts/content’, ‘post’)) loads partial templates like headers or loops, promoting modular code. Freelancers use it to create maintainable themes, while enterprise architects leverage it for scalable, reusable template structures.
What is WP_Query in WordPress?
WP_Query is a PHP class used to retrieve posts or custom post types from the WordPress database.
WP_Query allows custom queries (e.g., $query = new WP_Query(array(‘posts_per_page’ => 5))) to display specific content. Freelancers use it for custom loops in themes, while enterprise architects optimize queries for performance in high-traffic sites.
What is the purpose of the_content()?
the_content() outputs the main content of a post or page in the WordPress Loop.
Used within the Loop, the_content() displays post/page content, applying filters for formatting. Freelancers use it in custom templates, while enterprise architects ensure it’s optimized for dynamic content delivery in large-scale systems.
What does get_the_title() do?
get_the_title() retrieves the title of a post or page as a string.
Unlike the_title() which echoes the title, get_the_title() returns it for use in variables or conditions (e.g., $title = get_the_title()). Freelancers use it for custom layouts, while enterprise architects integrate it into data-driven applications.
What is the add_action() function?
add_action() attaches a custom function to a WordPress action hook to run at specific points.
For example, add_action(‘wp_enqueue_scripts’, ‘my_scripts’) runs a function when scripts are enqueued. Freelancers use actions for plugin or theme customizations, while enterprise architects use them for modular, extensible system design.
What is the add_filter()
add_filter() modifies data by attaching a function to a WordPress filter hook.
Filters like add_filter(‘the_content’, ‘my_content_filter’) alter output, such as adding text to post content. Freelancers use filters for client-specific tweaks, while enterprise architects apply them for consistent data transformations across systems.
What is the WordPress template hierarchy?
The template hierarchy determines which PHP template file WordPress uses to display content.
Files like single.php or page.php are chosen based on content type (e.g., post, page, category). Freelancers design custom templates within this hierarchy, while enterprise architects use it to ensure scalable, predictable page rendering.
What is functions.php in WordPress?
functions.php is a theme file for adding custom PHP code to extend functionality.
Located in the theme folder, it’s used for hooks, custom functions, or enqueuing scripts. Freelancers add client-specific features here, while enterprise architects ensure its code is optimized and secure for large deployments.
What does wp_enqueue_style() do?
wp_enqueue_style() loads CSS files in WordPress, ensuring proper dependency management.
For example, wp_enqueue_style(‘my-style’, get_stylesheet_uri()) adds a stylesheet. Freelancers use it to load custom styles, while enterprise architects ensure efficient asset loading for performance in complex sites.
What does wp_enqueue_script() do?
wp_enqueue_script() loads JavaScript files in WordPress with dependency control.
For example, wp_enqueue_script(‘my-script’, get_template_directory_uri() . ‘/js/script.js’, array(‘jquery’)) loads a script. Freelancers use it for custom interactivity, while enterprise architects optimize script loading for scalability.
What is a WordPress hook?
A hook is a mechanism (action or filter) that allows developers to modify or extend WordPress functionality.
Hooks like init or the_excerpt let developers inject custom code. Freelancers use hooks for tailored solutions, while enterprise architects rely on them for modular integrations in large systems.
What is the init hook?
The init hook runs after WordPress initializes, ideal for registering post types or taxonomies.
For example, add_action(‘init’, ‘register_my_post_type’) sets up custom content. Freelancers use it for client-specific content structures, while enterprise architects leverage it for scalable data models.
What is get_option()?
get_option() retrieves a value from the WordPress options table.
For example, get_option(‘siteurl’) gets the site URL. Freelancers use it to access or display settings, while enterprise architects integrate options into system configurations for dynamic functionality.
What is update_option()?
update_option() saves or updates a value in the WordPress options table.
For example, update_option(‘my_setting’, ‘value’) stores custom data. Freelancers use it for plugin settings, while enterprise architects manage large-scale configuration data with it.
What is register_post_type()?
register_post_type() creates a custom post type in WordPress.
For example, register_post_type(‘portfolio’, array(‘public’ => true)) adds a portfolio post type. Freelancers use it for client-specific content, while enterprise architects design custom post types for structured enterprise data.
What is register_taxonomy()?
register_taxonomy() creates a custom taxonomy for organizing content.
For example, register_taxonomy(‘genre’, ‘book’) adds a genre taxonomy for books. Freelancers use it to organize client content, while enterprise architects create taxonomies for complex data relationships.
What is wp_head()?
wp_head() outputs meta tags, scripts, and styles in the <head> section of a WordPress site.
Placed in header.php, it triggers the wp_head action hook for enqueued assets. Freelancers ensure it’s included in themes, while enterprise architects optimize its output for performance.
What is wp_footer()?
wp_footer() outputs scripts and content in the footer of a WordPress site.
Placed in footer.php, it triggers the wp_footer action hook for scripts like analytics. Freelancers use it for client-specific scripts, while enterprise architects ensure efficient footer asset loading.
What is is_page()?
is_page() checks if the current request is for a specific page.
For example, if (is_page(‘about’)) runs code only on the About page. Freelancers use it for conditional logic in templates, while enterprise architects apply it for targeted functionality in complex sites.
What is is_single()?
is_single() checks if the current request is for a single post or custom post type.
For example, if (is_single(‘my-post’)) targets a specific post. Freelancers use it for custom post layouts, while enterprise architects leverage it for precise content rendering.
What is wp_login_url()?
wp_login_url() returns the URL of the WordPress login page.
For example, echo wp_login_url() outputs the login link. Freelancers use it for custom login redirects, while enterprise architects integrate it into secure authentication workflows.